From c48bebc9ae36ab86f2b9024c0960b4d7837e4c2f Mon Sep 17 00:00:00 2001 From: Andy Green Date: Sat, 2 Jan 2021 05:31:31 +0000 Subject: [PATCH] h2: post: http_action: issue _HTTP and consume deferred body when resuming When we have to defer http_action for a stream because we may not have any writeability, we stash any incoming body on the rx buflist for the wsi which is good. But when we resume under some conditions, we don't issue the _HTTP cb and don't drain the stashed body. It's cleaned out in the close flow, but it's broken. This makes the deferred resume flow do the right thing under those conditions. --- lib/roles/h2/ops-h2.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/roles/h2/ops-h2.c b/lib/roles/h2/ops-h2.c index 6e2a81f84..8712dfed1 100644 --- a/lib/roles/h2/ops-h2.c +++ b/lib/roles/h2/ops-h2.c @@ -767,7 +767,9 @@ rops_callback_on_writable_h2(struct lws *wsi) static int lws_h2_bind_for_post_before_action(struct lws *wsi) { + uint8_t *buffered; const char *p; + size_t blen; p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_METHOD); if (p && !strcmp(p, "POST")) { @@ -808,9 +810,30 @@ lws_h2_bind_for_post_before_action(struct lws *wsi) return 1; } + { + int uri_len = 0; + char *uri_ptr = NULL; + + if (lws_http_get_uri_and_method(wsi, &uri_ptr, &uri_len) >= 0) + wsi->a.protocol->callback(wsi, LWS_CALLBACK_HTTP, + wsi->user_space, uri_ptr, (size_t)uri_len); + } + lwsl_info("%s: setting LRS_BODY from 0x%x (%s)\n", __func__, (int)wsi->wsistate, wsi->a.protocol->name); + lwsi_set_state(wsi, LRS_BODY); + + /* + * Dump any stashed body + */ + + while ((blen = lws_buflist_next_segment_len(&wsi->buflist, &buffered))) { + if (wsi->a.protocol->callback(wsi, LWS_CALLBACK_HTTP_BODY, + wsi->user_space, buffered, blen)) + return 1; + lws_buflist_use_segment(&wsi->buflist, blen); + } } return 0;