From 4d5c57d62e603cbadf6b896489ae49bb197b6fe8 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 26 Jul 2016 22:13:00 +0000 Subject: http_response: drop bodies for non-compliant responses Rack::Lint-compliant applications wouldn't have this problem; but apparently public-facing Rack servers (webrick/puma/thin) all implement this; so there is precedence for implementing this in yahns itself. --- test/test_response.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'test/test_response.rb') diff --git a/test/test_response.rb b/test/test_response.rb index a71fd65..34a4c90 100644 --- a/test/test_response.rb +++ b/test/test_response.rb @@ -9,6 +9,48 @@ class TestResponse < Testcase alias setup server_helper_setup alias teardown server_helper_teardown + def test_auto_head + err = @err + cfg = Yahns::Config.new + host, port = @srv.addr[3], @srv.addr[1] + str = "HELLO WORLD\n" + cfg.instance_eval do + GTL.synchronize do + app = Rack::Builder.new do + use Rack::ContentLength + use Rack::ContentType, "text/plain" + run(lambda do |env| + case env['PATH_INFO'] + when '/'; return [ 200, {}, [ str ] ] + when '/304'; return [ 304, {}, [ str ] ] + else + abort 'unsupported' + end + end) + end + app(:rack, app) { listen "#{host}:#{port}" } + end + logger(Logger.new(err.path)) + end + pid = mkserver(cfg) + s = TCPSocket.new(host, port) + s.write("HEAD / HTTP/1.0\r\n\r\n") + assert s.wait(30), "IO wait failed" + buf = s.read + assert_match %r{\r\n\r\n\z}, buf + s.close + + s = TCPSocket.new(host, port) + s.write("GET /304 HTTP/1.0\r\n\r\n") + assert s.wait(30), "IO wait failed" + buf = s.read + assert_match %r{\r\n\r\n\z}, buf + assert_match %r{\b304\b}, buf + s.close + ensure + quit_wait(pid) + end + def test_response_time_empty_body err = @err cfg = Yahns::Config.new -- cgit v1.2.3-24-ge0c7