Mercurial > prosody-hg
comparison spec/net_http_parser_spec.lua @ 13378:db30ffbf2090 0.12
net.http.parser: Reject overlarge header section earlier
This case would eventually be rejected by the buffer size limit.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Wed, 23 Aug 2023 12:18:34 +0200 |
| parents | 94a99330ce87 |
| children | 79a6598cef0b |
comparison
equal
deleted
inserted
replaced
| 13291:24070d47a6e7 | 13378:db30ffbf2090 |
|---|---|
| 165 ":)\n" | 165 ":)\n" |
| 166 }; | 166 }; |
| 167 } | 167 } |
| 168 ); | 168 ); |
| 169 end); | 169 end); |
| 170 | |
| 171 it("should reject very large request heads", function() | |
| 172 local finished = false; | |
| 173 local success_cb = spy.new(function() | |
| 174 finished = true; | |
| 175 end) | |
| 176 local error_cb = spy.new(function() | |
| 177 finished = true; | |
| 178 end) | |
| 179 local parser = http_parser.new(success_cb, error_cb, "server", function() | |
| 180 return { head_size_limit = 1024; body_size_limit = 1024; buffer_size_limit = 2048 }; | |
| 181 end) | |
| 182 parser:feed("GET / HTTP/1.1\r\n"); | |
| 183 for i = 1, 64 do -- * header line > buffer_size_limit | |
| 184 parser:feed(string.format("Header-%04d: Yet-AnotherValue\r\n", i)); | |
| 185 if finished then | |
| 186 -- should hit an error around half-way | |
| 187 break | |
| 188 end | |
| 189 end | |
| 190 if not finished then | |
| 191 parser:feed("\r\n") | |
| 192 end | |
| 193 assert.spy(success_cb).was_called(0); | |
| 194 assert.spy(error_cb).was_called(1); | |
| 195 assert.spy(error_cb).was_called_with("header-too-large"); | |
| 196 end) | |
| 170 end); | 197 end); |
| 171 | 198 |
| 172 it("should handle large chunked responses", function () | 199 it("should handle large chunked responses", function () |
| 173 local data = io.open("spec/inputs/http/httpstream-chunked-test.txt", "rb"):read("*a"); | 200 local data = io.open("spec/inputs/http/httpstream-chunked-test.txt", "rb"):read("*a"); |
| 174 | 201 |
