Comparison

spec/net_http_parser_spec.lua @ 11021:9673c95895fb

net.http.parser: Allow specifying sink for large request bodies This enables uses such as saving uploaded files directly to a file on disk or streaming parsing of payloads. See #726
author Kim Alvefur <zash@zash.se>
date Sat, 01 Aug 2020 18:41:23 +0200
parent 10497:a9fb553b6dbb
child 11030:388f599f66d1
comparison
equal deleted inserted replaced
11020:7076ed654ac9 11021:9673c95895fb
1 local http_parser = require "net.http.parser"; 1 local http_parser = require "net.http.parser";
2 2
3 local function test_stream(stream, expect) 3 local function test_stream(stream, expect)
4 local success_cb = spy.new(function (packet) 4 local success_cb = spy.new(function (packet)
5 assert.is_table(packet); 5 assert.is_table(packet);
6 assert.is_equal(expect.body, packet.body); 6 if packet.body ~= false then
7 assert.is_equal(expect.body, packet.body);
8 end
7 end); 9 end);
8 10
9 stream = stream:gsub("\n", "\r\n"); 11 stream = stream:gsub("\n", "\r\n");
10 local parser = http_parser.new(success_cb, error, stream:sub(1,4) == "HTTP" and "client" or "server") 12 local parser = http_parser.new(success_cb, error, stream:sub(1,4) == "HTTP" and "client" or "server")
11 for chunk in stream:gmatch("..?.?") do 13 for chunk in stream:gmatch("..?.?") do
77 0 79 0
78 80
79 81
80 ]], 82 ]],
81 { 83 {
82 body = "Hello", count = 1; 84 body = "Hello", count = 2;
83 } 85 }
84 ); 86 );
85 end); 87 end);
86 88
87 it("should handle a stream of responses", function () 89 it("should handle a stream of responses", function ()
106 0 108 0
107 109
108 110
109 ]], 111 ]],
110 { 112 {
111 body = "Hello", count = 2; 113 body = "Hello", count = 3;
112 } 114 }
113 ); 115 );
114 end); 116 end);
115 end); 117 end);
116 end); 118 end);