Software /
code /
prosody
Annotate
spec/net_http_parser_spec.lua @ 13025:b7d0c1d75a37
mod_csi: Add metrics, covering changes and totals
Motivation: Investigating clients that seem to forget to set CSI.
Also, of course, MORE GRAPHS!
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 06 Apr 2023 08:01:55 +0200 |
parent | 12889:94a99330ce87 |
rev | line source |
---|---|
10497
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
1 local http_parser = require "net.http.parser"; |
11030
388f599f66d1
net.http.parser: Add failing test for (large?) chunk-encoded responses
Matthew Wild <mwild1@gmail.com>
parents:
11021
diff
changeset
|
2 local sha1 = require "util.hashes".sha1; |
10497
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
3 |
11033
cb5555443852
net.http.parser: Allow configuration of the chunk size fed to the parser
Matthew Wild <mwild1@gmail.com>
parents:
11032
diff
changeset
|
4 local parser_input_bytes = 3; |
cb5555443852
net.http.parser: Allow configuration of the chunk size fed to the parser
Matthew Wild <mwild1@gmail.com>
parents:
11032
diff
changeset
|
5 |
11032
28de68414750
net.http.parser: Switch tests so that CRLF conversion of input data is optional
Matthew Wild <mwild1@gmail.com>
parents:
11031
diff
changeset
|
6 local function CRLF(s) |
28de68414750
net.http.parser: Switch tests so that CRLF conversion of input data is optional
Matthew Wild <mwild1@gmail.com>
parents:
11031
diff
changeset
|
7 return (s:gsub("\n", "\r\n")); |
28de68414750
net.http.parser: Switch tests so that CRLF conversion of input data is optional
Matthew Wild <mwild1@gmail.com>
parents:
11031
diff
changeset
|
8 end |
28de68414750
net.http.parser: Switch tests so that CRLF conversion of input data is optional
Matthew Wild <mwild1@gmail.com>
parents:
11031
diff
changeset
|
9 |
10497
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
10 local function test_stream(stream, expect) |
12889
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
11 local chunks_processed = 0; |
10497
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
12 local success_cb = spy.new(function (packet) |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
13 assert.is_table(packet); |
11021
9673c95895fb
net.http.parser: Allow specifying sink for large request bodies
Kim Alvefur <zash@zash.se>
parents:
10497
diff
changeset
|
14 if packet.body ~= false then |
9673c95895fb
net.http.parser: Allow specifying sink for large request bodies
Kim Alvefur <zash@zash.se>
parents:
10497
diff
changeset
|
15 assert.is_equal(expect.body, packet.body); |
9673c95895fb
net.http.parser: Allow specifying sink for large request bodies
Kim Alvefur <zash@zash.se>
parents:
10497
diff
changeset
|
16 end |
12889
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
17 if expect.chunks then |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
18 if chunks_processed == 0 then |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
19 assert.is_true(packet.partial); |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
20 packet.body_sink = { |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
21 write = function (_, data) |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
22 chunks_processed = chunks_processed + 1; |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
23 assert.equal(expect.chunks[chunks_processed], data); |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
24 return true; |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
25 end; |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
26 }; |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
27 end |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
28 end |
10497
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
29 end); |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
30 |
12889
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
31 local function options_cb() |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
32 return { |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
33 -- Force streaming API mode |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
34 body_size_limit = expect.chunks and 0 or nil; |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
35 buffer_size_limit = 10*1024*2; |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
36 }; |
10497
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
37 end |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
38 |
12889
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
39 local parser = http_parser.new(success_cb, error, (stream[1] or stream):sub(1,4) == "HTTP" and "client" or "server", options_cb) |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
40 if type(stream) == "string" then |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
41 for chunk in stream:gmatch("."..string.rep(".?", parser_input_bytes-1)) do |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
42 parser:feed(chunk); |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
43 end |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
44 else |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
45 for _, chunk in ipairs(stream) do |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
46 parser:feed(chunk); |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
47 end |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
48 end |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
49 |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
50 if expect.chunks then |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
51 assert.equal(chunks_processed, #expect.chunks); |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
52 end |
10497
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
53 assert.spy(success_cb).was_called(expect.count or 1); |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
54 end |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
55 |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
56 |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
57 describe("net.http.parser", function() |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
58 describe("parser", function() |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
59 it("should handle requests with no content-length or body", function () |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
60 test_stream( |
11032
28de68414750
net.http.parser: Switch tests so that CRLF conversion of input data is optional
Matthew Wild <mwild1@gmail.com>
parents:
11031
diff
changeset
|
61 CRLF[[ |
8236
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
62 GET / HTTP/1.1 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
63 Host: example.com |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
64 |
10497
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
65 ]], |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
66 { |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
67 body = ""; |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
68 } |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
69 ); |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
70 end); |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
71 |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
72 it("should handle responses with empty body", function () |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
73 test_stream( |
11032
28de68414750
net.http.parser: Switch tests so that CRLF conversion of input data is optional
Matthew Wild <mwild1@gmail.com>
parents:
11031
diff
changeset
|
74 CRLF[[ |
8236
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
75 HTTP/1.1 200 OK |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
76 Content-Length: 0 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
77 |
10497
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
78 ]], |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
79 { |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
80 body = ""; |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
81 } |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
82 ); |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
83 end); |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
84 |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
85 it("should handle simple responses", function () |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
86 test_stream( |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
87 |
11032
28de68414750
net.http.parser: Switch tests so that CRLF conversion of input data is optional
Matthew Wild <mwild1@gmail.com>
parents:
11031
diff
changeset
|
88 CRLF[[ |
8236
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
89 HTTP/1.1 200 OK |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
90 Content-Length: 7 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
91 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
92 Hello |
10497
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
93 ]], |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
94 { |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
95 body = "Hello\r\n", count = 1; |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
96 } |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
97 ); |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
98 end); |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
99 |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
100 it("should handle chunked encoding in responses", function () |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
101 test_stream( |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
102 |
11032
28de68414750
net.http.parser: Switch tests so that CRLF conversion of input data is optional
Matthew Wild <mwild1@gmail.com>
parents:
11031
diff
changeset
|
103 CRLF[[ |
10497
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
104 HTTP/1.1 200 OK |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
105 Transfer-Encoding: chunked |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
106 |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
107 1 |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
108 H |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
109 1 |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
110 e |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
111 2 |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
112 ll |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
113 1 |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
114 o |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
115 0 |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
116 |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
117 |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
118 ]], |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
119 { |
12882
9ed628635dc6
net.http.parser: Improve handling of responses without content-length
Matthew Wild <mwild1@gmail.com>
parents:
11033
diff
changeset
|
120 body = "Hello", count = 3; |
10497
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
121 } |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
122 ); |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
123 end); |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
124 |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
125 it("should handle a stream of responses", function () |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
126 test_stream( |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
127 |
11032
28de68414750
net.http.parser: Switch tests so that CRLF conversion of input data is optional
Matthew Wild <mwild1@gmail.com>
parents:
11031
diff
changeset
|
128 CRLF[[ |
10497
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
129 HTTP/1.1 200 OK |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
130 Content-Length: 5 |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
131 |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
132 Hello |
8236
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
133 HTTP/1.1 200 OK |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
134 Transfer-Encoding: chunked |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
135 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
136 1 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
137 H |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
138 1 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
139 e |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
140 2 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
141 ll |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
142 1 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
143 o |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
144 0 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
145 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
146 |
10497
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
147 ]], |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
148 { |
12882
9ed628635dc6
net.http.parser: Improve handling of responses without content-length
Matthew Wild <mwild1@gmail.com>
parents:
11033
diff
changeset
|
149 body = "Hello", count = 4; |
10497
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
150 } |
a9fb553b6dbb
net.http.parser tests: Expand tests to include validation of results
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
151 ); |
8236
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
152 end); |
12889
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
153 |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
154 it("should correctly find chunk boundaries", function () |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
155 test_stream({ |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
156 |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
157 CRLF[[ |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
158 HTTP/1.1 200 OK |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
159 Transfer-Encoding: chunked |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
160 |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
161 ]].."3\r\n:)\n\r\n"}, |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
162 { |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
163 count = 1; -- Once (partial) |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
164 chunks = { |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
165 ":)\n" |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
166 }; |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
167 } |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
168 ); |
94a99330ce87
net.http.parser: Fix off-by-one error in chunk parser
Matthew Wild <mwild1@gmail.com>
parents:
12882
diff
changeset
|
169 end); |
8236
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
170 end); |
11030
388f599f66d1
net.http.parser: Add failing test for (large?) chunk-encoded responses
Matthew Wild <mwild1@gmail.com>
parents:
11021
diff
changeset
|
171 |
11032
28de68414750
net.http.parser: Switch tests so that CRLF conversion of input data is optional
Matthew Wild <mwild1@gmail.com>
parents:
11031
diff
changeset
|
172 it("should handle large chunked responses", function () |
11031
57739c591a8c
net.http.parser: Fix incorrect path in test
Matthew Wild <mwild1@gmail.com>
parents:
11030
diff
changeset
|
173 local data = io.open("spec/inputs/http/httpstream-chunked-test.txt", "rb"):read("*a"); |
11030
388f599f66d1
net.http.parser: Add failing test for (large?) chunk-encoded responses
Matthew Wild <mwild1@gmail.com>
parents:
11021
diff
changeset
|
174 |
388f599f66d1
net.http.parser: Add failing test for (large?) chunk-encoded responses
Matthew Wild <mwild1@gmail.com>
parents:
11021
diff
changeset
|
175 -- Just a sanity check... text editors and things may mess with line endings, etc. |
388f599f66d1
net.http.parser: Add failing test for (large?) chunk-encoded responses
Matthew Wild <mwild1@gmail.com>
parents:
11021
diff
changeset
|
176 assert.equal("25930f021785ae14053a322c2dbc1897c3769720", sha1(data, true), "test data malformed"); |
388f599f66d1
net.http.parser: Add failing test for (large?) chunk-encoded responses
Matthew Wild <mwild1@gmail.com>
parents:
11021
diff
changeset
|
177 |
388f599f66d1
net.http.parser: Add failing test for (large?) chunk-encoded responses
Matthew Wild <mwild1@gmail.com>
parents:
11021
diff
changeset
|
178 test_stream(data, { |
12882
9ed628635dc6
net.http.parser: Improve handling of responses without content-length
Matthew Wild <mwild1@gmail.com>
parents:
11033
diff
changeset
|
179 body = string.rep("~", 11085), count = 3; |
11030
388f599f66d1
net.http.parser: Add failing test for (large?) chunk-encoded responses
Matthew Wild <mwild1@gmail.com>
parents:
11021
diff
changeset
|
180 }); |
388f599f66d1
net.http.parser: Add failing test for (large?) chunk-encoded responses
Matthew Wild <mwild1@gmail.com>
parents:
11021
diff
changeset
|
181 end); |
8236
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
182 end); |