diff --git a/lib/roles/h2/http2.c b/lib/roles/h2/http2.c index ae8a7e880..4f6589dc8 100644 --- a/lib/roles/h2/http2.c +++ b/lib/roles/h2/http2.c @@ -1641,6 +1641,27 @@ lws_h2_parse_end_of_frame(struct lws *wsi) } #if defined(LWS_WITH_CLIENT) + + /* + * If we already had the END_STREAM along with the END_HEADERS, + * we have already transitioned to STATE_CLOSED and we are not + * going to be doing anything further on this stream. + * + * In that case handle the transaction completion and + * finalize the stream for the peer + */ + + if (h2n->swsi->h2.h2_state == LWS_H2_STATE_CLOSED && + h2n->swsi->client_mux_substream) { + + lws_h2_rst_stream(h2n->swsi, H2_ERR_NO_ERROR, + "client done"); + + if (lws_http_transaction_completed_client(h2n->swsi)) + lwsl_debug("tx completed returned close\n"); + break; + } + if (h2n->swsi->client_mux_substream) { lwsl_info("%s: %s: headers: client path (h2 state %s)\n", __func__, lws_wsi_tag(wsi), @@ -1692,27 +1713,6 @@ lws_h2_parse_end_of_frame(struct lws *wsi) break; } -#if defined(LWS_WITH_CLIENT) - - /* - * If we already had the END_STREAM along with the END_HEADERS, - * we have already transitioned to STATE_CLOSED and we are not - * going to be doing anything further on this stream. - * - * In that case handle the transaction completion and - * finalize the stream for the peer - */ - - if (h2n->swsi->h2.h2_state == LWS_H2_STATE_CLOSED && - h2n->swsi->client_mux_substream) { - - lws_h2_rst_stream(h2n->swsi, H2_ERR_NO_ERROR, - "client done"); - - if (lws_http_transaction_completed_client(h2n->swsi)) - lwsl_debug("tx completed returned close\n"); - } else -#endif { lwsl_debug("%s: setting DEF_ACT from 0x%x\n", __func__, (unsigned int)h2n->swsi->wsistate); diff --git a/lib/roles/http/client/client-http.c b/lib/roles/http/client/client-http.c index 2487a3b06..e600bd651 100644 --- a/lib/roles/http/client/client-http.c +++ b/lib/roles/http/client/client-http.c @@ -933,10 +933,12 @@ lws_client_interpret_server_handshake(struct lws *wsi) /* * Did we get a response from the server with an explicit - * content-length of zero? If so, this transaction is already + * content-length of zero? If so, and it's not H2 which will + * notice it via END_STREAM, this transaction is already * completed at the end of the header processing... */ - if (lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH) && + if (!wsi->mux_substream && !wsi->client_mux_substream && + lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH) && !wsi->http.rx_content_length) return !!lws_http_transaction_completed_client(wsi);