diff options
author | Jean Boussier <jean.boussier@gmail.com> | 2020-07-16 11:39:30 +0200 |
---|---|---|
committer | Eric Wong <bofh@yhbt.net> | 2020-07-16 11:57:22 +0000 |
commit | 92f587c191c96e201984d47ccdaf43a1bff2fc17 (patch) | |
tree | f4de27b542a7fa9f72ae002636b11b0c680debdf /test | |
parent | 17de306edbbf4140df7ec49dbb7e26e59d33c0f9 (diff) | |
download | unicorn-92f587c191c96e201984d47ccdaf43a1bff2fc17.tar.gz |
While not part of the rack spec, this API is exposed by both puma and falcon, and Rails use it when available. The 103 Early Hints response code is specified in RFC 8297.
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/test_server.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/unit/test_server.rb b/test/unit/test_server.rb index 8096955..d706243 100644 --- a/test/unit/test_server.rb +++ b/test/unit/test_server.rb @@ -23,6 +23,16 @@ class TestHandler end end +class TestEarlyHintsHandler + def call(env) + while env['rack.input'].read(4096) + end + env['rack.early_hints'].call( + "Link" => "</style.css>; rel=preload; as=style\n</script.js>; rel=preload" + ) + [200, { 'Content-Type' => 'text/plain' }, ['hello!\n']] + end +end class WebServerTest < Test::Unit::TestCase @@ -84,6 +94,26 @@ class WebServerTest < Test::Unit::TestCase tmp.close! end + def test_early_hints + teardown + redirect_test_io do + @server = HttpServer.new(TestEarlyHintsHandler.new, + :listeners => [ "127.0.0.1:#@port"], + :early_hints => true) + @server.start + end + + sock = TCPSocket.new('127.0.0.1', @port) + sock.syswrite("GET / HTTP/1.0\r\n\r\n") + + responses = sock.sysread(4096) + assert_match %r{\AHTTP/1.[01] 103\b}, responses + assert_match %r{^Link: </style\.css>}, responses + assert_match %r{^Link: </script\.js>}, responses + + assert_match %r{^HTTP/1.[01] 200\b}, responses + end + def test_broken_app teardown app = lambda { |env| raise RuntimeError, "hello" } |