Changeset

11032:28de68414750

net.http.parser: Switch tests so that CRLF conversion of input data is optional
author Matthew Wild <mwild1@gmail.com>
date Fri, 21 Aug 2020 14:12:51 +0100
parents 11031:57739c591a8c
children 11033:cb5555443852
files spec/net_http_parser_spec.lua
diffstat 1 files changed, 10 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/spec/net_http_parser_spec.lua	Fri Aug 21 13:49:10 2020 +0100
+++ b/spec/net_http_parser_spec.lua	Fri Aug 21 14:12:51 2020 +0100
@@ -1,6 +1,10 @@
 local http_parser = require "net.http.parser";
 local sha1 = require "util.hashes".sha1;
 
+local function CRLF(s)
+	return (s:gsub("\n", "\r\n"));
+end
+
 local function test_stream(stream, expect)
 	local success_cb = spy.new(function (packet)
 		assert.is_table(packet);
@@ -9,7 +13,6 @@
 		end
 	end);
 
-	stream = stream:gsub("\n", "\r\n");
 	local parser = http_parser.new(success_cb, error, stream:sub(1,4) == "HTTP" and "client" or "server")
 	for chunk in stream:gmatch("..?.?") do
 		parser:feed(chunk);
@@ -23,7 +26,7 @@
 	describe("parser", function()
 		it("should handle requests with no content-length or body", function ()
 			test_stream(
-[[
+CRLF[[
 GET / HTTP/1.1
 Host: example.com
 
@@ -36,7 +39,7 @@
 
 		it("should handle responses with empty body", function ()
 			test_stream(
-[[
+CRLF[[
 HTTP/1.1 200 OK
 Content-Length: 0
 
@@ -50,7 +53,7 @@
 		it("should handle simple responses", function ()
 			test_stream(
 
-[[
+CRLF[[
 HTTP/1.1 200 OK
 Content-Length: 7
 
@@ -65,7 +68,7 @@
 		it("should handle chunked encoding in responses", function ()
 			test_stream(
 
-[[
+CRLF[[
 HTTP/1.1 200 OK
 Transfer-Encoding: chunked
 
@@ -90,7 +93,7 @@
 		it("should handle a stream of responses", function ()
 			test_stream(
 
-[[
+CRLF[[
 HTTP/1.1 200 OK
 Content-Length: 5
 
@@ -117,7 +120,7 @@
 		end);
 	end);
 
-	pending("should handle large chunked responses", function ()
+	it("should handle large chunked responses", function ()
 		local data = io.open("spec/inputs/http/httpstream-chunked-test.txt", "rb"):read("*a");
 
 		-- Just a sanity check... text editors and things may mess with line endings, etc.