Mercurial > prosody-hg
comparison net/http/parser.lua @ 14086:79a6598cef0b 13.0
net.http.parser: Fix handling of chunked request
How to determine whether a request/response has a body depends on
different things for requests and responses, which was not reflected in
the code.
Test case based on
curl http://localhost:5280/debug -H "Transfer-Encoding: chunked" --json '{"json":true}'
Thanks isafashiondev
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 20 Feb 2026 15:08:03 +0100 |
| parents | 977d92aff563 |
| children | 948bda5ed45f |
comparison
equal
deleted
inserted
replaced
| 14073:dfbc60d47668 | 14086:79a6598cef0b |
|---|---|
| 91 if not method then error = true; return error_cb("invalid-status-line"); end | 91 if not method then error = true; return error_cb("invalid-status-line"); end |
| 92 end | 92 end |
| 93 end | 93 end |
| 94 end | 94 end |
| 95 if not first_line then error = true; return error_cb("invalid-status-line"); end | 95 if not first_line then error = true; return error_cb("invalid-status-line"); end |
| 96 chunked = have_body and headers["transfer-encoding"] == "chunked"; | |
| 97 len = tonumber(headers["content-length"]); -- TODO check for invalid len | 96 len = tonumber(headers["content-length"]); -- TODO check for invalid len |
| 98 if client then | 97 if client then |
| 98 -- The presence of a message body in a response, as detailed in Section 6.3, depends on both the request method to which it is responding | |
| 99 -- and the response status code. | |
| 100 -- -- RFC9112 Section 6 | |
| 101 chunked = have_body and headers["transfer-encoding"] == "chunked"; | |
| 99 -- FIXME handle '100 Continue' response (by skipping it) | 102 -- FIXME handle '100 Continue' response (by skipping it) |
| 100 if not have_body then len = 0; end | 103 if not have_body then len = 0; end |
| 101 packet = { | 104 packet = { |
| 102 code = status_code; | 105 code = status_code; |
| 103 httpversion = httpversion; | 106 httpversion = httpversion; |
| 109 -- COMPAT the properties below are deprecated | 112 -- COMPAT the properties below are deprecated |
| 110 responseversion = httpversion; | 113 responseversion = httpversion; |
| 111 responseheaders = headers; | 114 responseheaders = headers; |
| 112 }; | 115 }; |
| 113 else | 116 else |
| 117 -- The presence of a message body in a request is signaled by a Content-Length or Transfer-Encoding header field. Request message framing | |
| 118 -- is independent of method semantics. | |
| 119 -- -- RFC9112 Section 6 | |
| 120 chunked = headers["transfer-encoding"] == "chunked"; | |
| 121 have_body = chunked or len; | |
| 114 local parsed_url; | 122 local parsed_url; |
| 115 if path:byte() == 47 then -- starts with / | 123 if path:byte() == 47 then -- starts with / |
| 116 local _path, _query = path:match("([^?]*).?(.*)"); | 124 local _path, _query = path:match("([^?]*).?(.*)"); |
| 117 if _query == "" then _query = nil; end | 125 if _query == "" then _query = nil; end |
| 118 parsed_url = { path = _path, query = _query }; | 126 parsed_url = { path = _path, query = _query }; |
