about summary refs log tree commit homepage
path: root/test/test_response.rb
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-07-26 22:13:00 +0000
committerEric Wong <e@80x24.org>2016-07-26 22:33:28 +0000
commit4d5c57d62e603cbadf6b896489ae49bb197b6fe8 (patch)
treee8946dae1d18adb055066d1a62fdcd839c6462d9 /test/test_response.rb
parentfd0e8f9ed47a5c9316be2306b4d21130c46d7218 (diff)
downloadyahns-4d5c57d62e603cbadf6b896489ae49bb197b6fe8.tar.gz
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.
Diffstat (limited to 'test/test_response.rb')
-rw-r--r--test/test_response.rb42
1 files changed, 42 insertions, 0 deletions
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