Software /
code /
prosody
Comparison
tests/test_net_http_parser.lua @ 7493:f67b7509ee28
tests: Add basic test for net.http.parser
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 12 Jul 2016 13:59:02 +0200 |
comparison
equal
deleted
inserted
replaced
7492:9a749cf8c1ba | 7493:f67b7509ee28 |
---|---|
1 local httpstreams = { [[ | |
2 GET / HTTP/1.1 | |
3 Host: example.com | |
4 | |
5 ]], [[ | |
6 HTTP/1.1 200 OK | |
7 Content-Length: 0 | |
8 | |
9 ]], [[ | |
10 HTTP/1.1 200 OK | |
11 Content-Length: 7 | |
12 | |
13 Hello | |
14 HTTP/1.1 200 OK | |
15 Transfer-Encoding: chunked | |
16 | |
17 1 | |
18 H | |
19 1 | |
20 e | |
21 2 | |
22 ll | |
23 1 | |
24 o | |
25 0 | |
26 | |
27 | |
28 ]] | |
29 } | |
30 | |
31 function new(new) | |
32 | |
33 for _, stream in ipairs(httpstreams) do | |
34 local success; | |
35 local function success_cb(packet) | |
36 success = true; | |
37 end | |
38 stream = stream:gsub("\n", "\r\n"); | |
39 local parser = new(success_cb, error, stream:sub(1,4) == "HTTP" and "client" or "server") | |
40 for chunk in stream:gmatch("..?.?") do | |
41 parser:feed(chunk); | |
42 end | |
43 | |
44 assert_is(success); | |
45 end | |
46 | |
47 end |