diff --git a/lib/roles/http/server/server.c b/lib/roles/http/server/server.c index 1a1aab85e..22fe94b3d 100644 --- a/lib/roles/http/server/server.c +++ b/lib/roles/http/server/server.c @@ -2954,8 +2954,21 @@ int lws_serve_http_file_fragment(struct lws *wsi) } #endif - poss = context->pt_serv_buf_size - (unsigned int)n - - LWS_H2_FRAME_HEADER_LENGTH; + poss = context->pt_serv_buf_size; + +#if defined(LWS_ROLE_H2) + /* + * If it's h2, restrict any lump that we are sending to the + * max h2 frame size the peer indicated he could handle in + * his SETTINGS + */ + nwsi = lws_get_network_wsi(wsi); + if (nwsi->h2.h2n && + poss > (lws_filepos_t)nwsi->h2.h2n->peer_set.s[H2SET_MAX_FRAME_SIZE]) + poss = (lws_filepos_t)nwsi->h2.h2n->peer_set.s[H2SET_MAX_FRAME_SIZE]; + + poss = poss - (lws_filepos_t)(n - LWS_H2_FRAME_HEADER_LENGTH); +#endif if (wsi->http.tx_content_length) if (poss > wsi->http.tx_content_remain) @@ -3017,18 +3030,6 @@ int lws_serve_http_file_fragment(struct lws *wsi) else n = lws_ptr_diff(p, pstart) + (int)amount; -#if defined(LWS_ROLE_H2) - /* - * If it's h2, restrict any lump that we are sending to the - * max h2 frame size the peer indicated he could handle in - * his SETTINGS - */ - nwsi = lws_get_network_wsi(wsi); - if (nwsi->h2.h2n && - n > (int)nwsi->h2.h2n->peer_set.s[H2SET_MAX_FRAME_SIZE]) - n = (int)nwsi->h2.h2n->peer_set.s[H2SET_MAX_FRAME_SIZE]; -#endif - lwsl_debug("%s: sending %d\n", __func__, n); if (n) {