Even zero is a valid content-length

This commit is contained in:
Alex Hultman
2019-02-04 00:39:45 +01:00
parent 5528e6f5fe
commit 0709ec05a6
2 changed files with 10 additions and 5 deletions
+1 -1
View File
@@ -176,7 +176,7 @@ public:
} }
/* This will add our mark */ /* This will add our mark */
res->end(); res->upgrade();
/* Move any backpressure */ /* Move any backpressure */
std::string backpressure(std::move(((AsyncSocketData<SSL> *) res->getHttpResponseData())->buffer)); std::string backpressure(std::move(((AsyncSocketData<SSL> *) res->getHttpResponseData())->buffer));
+9 -4
View File
@@ -82,7 +82,7 @@ private:
/* Returns true on success, indicating that it might be feasible to write more data. /* Returns true on success, indicating that it might be feasible to write more data.
* Will start timeout if stream reaches totalSize or write failure. */ * Will start timeout if stream reaches totalSize or write failure. */
bool internalEnd(std::string_view data, int totalSize, bool optional) { bool internalEnd(std::string_view data, int totalSize, bool optional, bool allowContentLength = true) {
/* Write status if not already done */ /* Write status if not already done */
writeStatus(HTTP_200_OK); writeStatus(HTTP_200_OK);
@@ -120,9 +120,9 @@ private:
/* Write mark, this propagates to WebSockets too */ /* Write mark, this propagates to WebSockets too */
writeMark(); writeMark();
/* Ending with no response should not leave any content-length */ /* WebSocket upgrades does not allow content-length */
if (totalSize) { if (allowContentLength) {
/* We have a known send size */ /* Even zero is a valid content-length */
Super::write("Content-Length: ", 16); Super::write("Content-Length: ", 16);
writeUnsigned(totalSize); writeUnsigned(totalSize);
Super::write("\r\n\r\n", 4); Super::write("\r\n\r\n", 4);
@@ -158,6 +158,11 @@ private:
} }
} }
/* This call is identical to end, but will never write content-length and is thus suitable for upgrades */
void upgrade() {
internalEnd({nullptr, 0}, 0, false, false);
}
public: public:
/* Immediately terminate this Http response */ /* Immediately terminate this Http response */
using Super::close; using Super::close;