1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

http: if no content length transaction completes at hangup

If you encounter an h1 transaction with no content length and you
parsed the headers, it actually means a hangup subsequently is an
indication of a correct transaction completion.  So take care to
do the _COMPLETION callback under those circumstances too.
This commit is contained in:
Andy Green 2020-05-19 18:34:38 +01:00
parent 073a59264a
commit 36bcae17ab
2 changed files with 33 additions and 1 deletions

View file

@ -327,7 +327,7 @@ set(PACKAGE "libwebsockets")
set(CPACK_PACKAGE_NAME "${PACKAGE}")
set(CPACK_PACKAGE_VERSION_MAJOR "4")
set(CPACK_PACKAGE_VERSION_MINOR "0")
set(CPACK_PACKAGE_VERSION_PATCH "10")
set(CPACK_PACKAGE_VERSION_PATCH "11")
set(CPACK_PACKAGE_RELEASE 1)
set(CPACK_GENERATOR "RPM")
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")

View file

@ -922,6 +922,21 @@ lws_client_interpret_server_handshake(struct lws *wsi)
!wsi->http.rx_content_length)
return !!lws_http_transaction_completed_client(wsi);
/*
* We can also get a case where it's http/1 and there's no
* content-length at all, so anything that comes is the body
* until it hangs up on us. With that situation, hanging up
* on us past this point should generate a valid
* LWS_CALLBACK_COMPLETED_CLIENT_HTTP.
*
* In that situation, he can't pipeline because in h1 there's
* no post-header in-band way to signal the end of the
* transaction except hangup.
*
* lws_http_transaction_completed_client() is the right guy to
* issue it when we see the peer has hung up on us.
*/
return 0;
}
@ -1231,6 +1246,23 @@ lws_http_client_read(struct lws *wsi, char **buf, int *len)
if (buffered < 0) {
lwsl_debug("%s: SSL capable error\n", __func__);
if (wsi->http.ah &&
wsi->http.ah->parser_state == WSI_PARSING_COMPLETE &&
!lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH))
/*
* We had the headers from this stream, but as there
* was no content-length: we had to wait until the
* stream ended to inform the user code the transaction
* has completed to the best of our knowledge
*/
if (lws_http_transaction_completed_client(wsi))
/*
* We're going to close anyway, but that api has
* warn_unused_result
*/
return -1;
return -1;
}