Skip to content

Commit

Permalink
Don't write mark in the middle of streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
uNetworkingAB committed Jan 29, 2019
1 parent 359873f commit eaa9467
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/HttpResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,17 @@ struct HttpResponse : public AsyncSocket<SSL> {
httpResponseData->state &= ~HttpResponseData<SSL>::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();
Expand Down Expand Up @@ -115,6 +117,9 @@ struct HttpResponse : public AsyncSocket<SSL> {
} else {
/* Write content-length on first call */
if (!(httpResponseData->state & HttpResponseData<SSL>::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 */
Expand Down Expand Up @@ -221,6 +226,9 @@ struct HttpResponse : public AsyncSocket<SSL> {
HttpResponseData<SSL> *httpResponseData = getHttpResponseData();

if (!(httpResponseData->state & HttpResponseData<SSL>::HTTP_WRITE_CALLED)) {
/* Write mark on first call to write */
writeMark();

writeHeader("Transfer-Encoding", "chunked");
httpResponseData->state |= HttpResponseData<SSL>::HTTP_WRITE_CALLED;
}
Expand Down

0 comments on commit eaa9467

Please sign in to comment.