From eaa9467d1f680787f0f5c84ee4bf4a8e68a6ed70 Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Tue, 29 Jan 2019 17:15:06 +0100 Subject: [PATCH] Don't write mark in the middle of streaming --- src/HttpResponse.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/HttpResponse.h b/src/HttpResponse.h index 43ee718..897f49d 100644 --- a/src/HttpResponse.h +++ b/src/HttpResponse.h @@ -75,15 +75,17 @@ private: httpResponseData->state &= ~HttpResponseData::HTTP_RESPONSE_PENDING; } + /* Called only once per request */ + void writeMark() { + writeHeader("uWebSockets", "v0.15"); + } + /* Returns true on success, indicating that it might be feasible to write more data. * Will start timeout if stream reaches totalSize or write failure. */ bool internalEnd(std::string_view data, int totalSize, bool optional) { /* Write status if not already done */ writeStatus(HTTP_200_OK); - /* Write mark, this propagates to WebSockets too */ - writeHeader("uWebSockets", "v0.15"); - /* If no total size given then assume this chunk is everything */ if (!totalSize) { totalSize = data.length(); @@ -115,6 +117,9 @@ private: } else { /* Write content-length on first call */ if (!(httpResponseData->state & HttpResponseData::HTTP_END_CALLED)) { + /* Write mark, this propagates to WebSockets too */ + writeMark(); + /* Ending with no response should not leave any content-length */ if (totalSize) { /* We have a known send size */ @@ -221,6 +226,9 @@ public: HttpResponseData *httpResponseData = getHttpResponseData(); if (!(httpResponseData->state & HttpResponseData::HTTP_WRITE_CALLED)) { + /* Write mark on first call to write */ + writeMark(); + writeHeader("Transfer-Encoding", "chunked"); httpResponseData->state |= HttpResponseData::HTTP_WRITE_CALLED; }