From 5dd1932f5f527ab68ff3a73073a38a9383773f3a Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Wed, 3 Apr 2019 03:29:44 +0200 Subject: [PATCH] Salvage fallback buffer from burning house --- src/App.h | 3 +++ src/HttpParser.h | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/src/App.h b/src/App.h index 042c7dc..0081b33 100644 --- a/src/App.h +++ b/src/App.h @@ -192,6 +192,9 @@ public: /* Move any backpressure */ std::string backpressure(std::move(((AsyncSocketData *) res->getHttpResponseData())->buffer)); + /* Keep any fallback buffer alive until we returned from open event, keeping req valid */ + std::string fallback(std::move(res->getHttpResponseData()->salvageFallbackBuffer())); + /* Destroy HttpResponseData */ res->getHttpResponseData()->~HttpResponseData(); diff --git a/src/HttpParser.h b/src/HttpParser.h index 28e48d4..0a312cc 100644 --- a/src/HttpParser.h +++ b/src/HttpParser.h @@ -221,6 +221,11 @@ private: public: + /* We do this to prolong the validity of parsed headers by keeping only the fallback buffer alive */ + std::string &&salvageFallbackBuffer() { + return std::move(fallback); + } + void *consumePostPadded(char *data, int length, void *user, fu2::unique_function &&requestHandler, fu2::unique_function &&dataHandler, fu2::unique_function &&errorHandler) { HttpRequest req;