From d4e5a295f2f9af1f815596656a185b11d7dabb29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Og=C3=B3rek?= Date: Sun, 12 Feb 2023 11:43:05 +0100 Subject: fix(ext/flash): Always send correct number of bytes when handling HEAD requests (#17740) This was not caught in the previous test case, as the response body was smaller than the size of `HEAD` response. This made `nwritten < responseLen` check in `writeFixedResponse` to fail, and not trigger `op_flash_respond_async` as a result. When the response body is larger than the `HEAD` though, as in the updated test case (`HEAD` i 120 bytes, where our response is 300 bytes), it would think that we still have something to send, and effectively panic, as `op_flash_respond` already removed the request from the pool. This change, makes the `handleResponse` function always calculate the number of bytes to transmit when `HEAD` request is encountered. Effectively ignoring `Content-Length` of the body, but still setting it correctly in the request header itself. Fixes https://github.com/denoland/deno/issues/17737 --- ext/flash/01_http.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ext') diff --git a/ext/flash/01_http.js b/ext/flash/01_http.js index 34b158e40..5152fd9e5 100644 --- a/ext/flash/01_http.js +++ b/ext/flash/01_http.js @@ -316,11 +316,13 @@ async function handleResponse( respBody, length, ); + // A HEAD request always ignores body, but includes the correct content-length size. + const responseLen = method === 1 ? core.byteLength(responseStr) : length; writeFixedResponse( serverId, i, responseStr, - length, + responseLen, !ws, // Don't close socket if there is a deferred websocket upgrade. respondFast, ); -- cgit v1.2.3