Don't leave content-length on empty response
This commit is contained in:
@@ -50,6 +50,10 @@ private:
|
||||
using StaticDispatch<SSL>::static_dispatch;
|
||||
public:
|
||||
|
||||
void registerTag() {
|
||||
|
||||
}
|
||||
|
||||
~TemplatedApp() {
|
||||
|
||||
}
|
||||
@@ -135,8 +139,6 @@ public:
|
||||
ExtensionsNegotiator<true> extensionsNegotiator(wantedOptions);
|
||||
extensionsNegotiator.readOffer(extensions);
|
||||
|
||||
std::cout << extensions << " => " << extensionsNegotiator.generateOffer() << std::endl;
|
||||
|
||||
/* Todo: remove these mid string copies */
|
||||
res->writeHeader("Sec-WebSocket-Extensions", extensionsNegotiator.generateOffer());
|
||||
|
||||
@@ -155,6 +157,8 @@ public:
|
||||
/* Add mark, we don't want to end anything */
|
||||
res->writeHeader("WebSocket-Server", "uWebSockets")->end();
|
||||
|
||||
/* todo: What about HttpResponseData here? */
|
||||
|
||||
/* Adopting a socket invalidates it, do not rely on it directly to carry any data */
|
||||
WebSocket<SSL, true> *webSocket = (WebSocket<SSL, true> *) StaticDispatch<SSL>::static_dispatch(us_ssl_socket_context_adopt_socket, us_socket_context_adopt_socket)(
|
||||
(typename StaticDispatch<SSL>::SOCKET_CONTEXT_TYPE *) webSocketContext, (typename StaticDispatch<SSL>::SOCKET_TYPE *) res, sizeof(WebSocketData) + sizeof(UserData));
|
||||
@@ -171,8 +175,7 @@ public:
|
||||
behavior.open(webSocket, req);
|
||||
}
|
||||
|
||||
// todo: perform all the checks such as shutdown, closed, etc!
|
||||
// bug? or does this happen automatically? no!
|
||||
/* We do not need to check for any close or shutdown here as we immediately return from get handler */
|
||||
|
||||
} else {
|
||||
/* For now we do not support having HTTP and websocket routes on the same URL */
|
||||
|
||||
@@ -41,13 +41,8 @@ protected:
|
||||
);
|
||||
}
|
||||
|
||||
// we need a type safe realType = getData<MiddleType>
|
||||
|
||||
/* Get socket extension */
|
||||
void *getExt() {
|
||||
|
||||
// we might have multiple inheritance so need to know the middle type
|
||||
|
||||
return static_dispatch(us_ssl_socket_ext, us_socket_ext)((SOCKET_TYPE *) this);
|
||||
}
|
||||
|
||||
|
||||
@@ -312,6 +312,7 @@ public:
|
||||
});
|
||||
}
|
||||
|
||||
// this can be removed? or at least set by default to something like Apache server does
|
||||
void onUnhandled(std::function<void(uWS::HttpResponse<SSL> *, uWS::HttpRequest *)> handler) {
|
||||
HttpContextData<SSL> *httpContextData = getSocketContextData();
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ private:
|
||||
};
|
||||
|
||||
HttpRouter<RouterData> router;
|
||||
void *upgradedWebSocket;
|
||||
void *upgradedWebSocket = nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+9
-4
@@ -95,10 +95,15 @@ private:
|
||||
} else {
|
||||
/* Write content-length on first call */
|
||||
if (!(httpResponseData->state & HttpResponseData<SSL>::HTTP_END_CALLED)) {
|
||||
/* We have a known send size */
|
||||
Super::write("Content-Length: ", 16);
|
||||
writeUnsigned(totalSize);
|
||||
Super::write("\r\n\r\n", 4);
|
||||
/* Ending with no response should not leave any content-length */
|
||||
if (totalSize) {
|
||||
/* We have a known send size */
|
||||
Super::write("Content-Length: ", 16);
|
||||
writeUnsigned(totalSize);
|
||||
Super::write("\r\n\r\n", 4);
|
||||
} else {
|
||||
Super::write("\r\n", 2);
|
||||
}
|
||||
|
||||
/* Mark end called */
|
||||
httpResponseData->state |= HttpResponseData<SSL>::HTTP_END_CALLED;
|
||||
|
||||
Reference in New Issue
Block a user