Mercurial > prosody-hg
comparison spec/net_http_parser_spec.lua @ 11033:cb5555443852
net.http.parser: Allow configuration of the chunk size fed to the parser
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 21 Aug 2020 14:14:29 +0100 |
| parents | 28de68414750 |
| children | 9ed628635dc6 |
comparison
equal
deleted
inserted
replaced
| 11032:28de68414750 | 11033:cb5555443852 |
|---|---|
| 1 local http_parser = require "net.http.parser"; | 1 local http_parser = require "net.http.parser"; |
| 2 local sha1 = require "util.hashes".sha1; | 2 local sha1 = require "util.hashes".sha1; |
| 3 | |
| 4 local parser_input_bytes = 3; | |
| 3 | 5 |
| 4 local function CRLF(s) | 6 local function CRLF(s) |
| 5 return (s:gsub("\n", "\r\n")); | 7 return (s:gsub("\n", "\r\n")); |
| 6 end | 8 end |
| 7 | 9 |
| 12 assert.is_equal(expect.body, packet.body); | 14 assert.is_equal(expect.body, packet.body); |
| 13 end | 15 end |
| 14 end); | 16 end); |
| 15 | 17 |
| 16 local parser = http_parser.new(success_cb, error, stream:sub(1,4) == "HTTP" and "client" or "server") | 18 local parser = http_parser.new(success_cb, error, stream:sub(1,4) == "HTTP" and "client" or "server") |
| 17 for chunk in stream:gmatch("..?.?") do | 19 for chunk in stream:gmatch("."..string.rep(".?", parser_input_bytes-1)) do |
| 18 parser:feed(chunk); | 20 parser:feed(chunk); |
| 19 end | 21 end |
| 20 | 22 |
| 21 assert.spy(success_cb).was_called(expect.count or 1); | 23 assert.spy(success_cb).was_called(expect.count or 1); |
| 22 end | 24 end |
