diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2015-08-17 18:48:00 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2015-08-18 16:19:31 +0900 |
commit | ec059733e3e63ac461e8477638ad5d0a7d65dc58 (patch) | |
tree | 93832299c0009803075b757e6a4d1e2e1590cddb | |
parent | 850af19b0259fafaa196175c45f72de1ec7f5084 (diff) | |
download | plum-ec059733e3e63ac461e8477638ad5d0a7d65dc58.tar.gz |
http_connection: raise LegacyHTTPError instead of sending 505 (HTTP Version Not Supported) HTTP/1.1 response
-rw-r--r-- | examples/non_tls_server.rb | 12 | ||||
-rw-r--r-- | lib/plum/errors.rb | 1 | ||||
-rw-r--r-- | lib/plum/http_connection.rb | 17 | ||||
-rw-r--r-- | test/plum/test_http_connection.rb | 5 |
4 files changed, 17 insertions, 18 deletions
diff --git a/examples/non_tls_server.rb b/examples/non_tls_server.rb index 804e3d2..54e4f19 100644 --- a/examples/non_tls_server.rb +++ b/examples/non_tls_server.rb @@ -105,6 +105,18 @@ loop do Thread.new { begin plum.run + rescue Plum::LegacyHTTPError + data = "Use modern web browser with HTTP/2 support." + + resp = "" + resp << "HTTP/1.1 505 HTTP Version Not Supported\r\n" + resp << "Content-Type: text/plain\r\n" + resp << "Content-Length: #{data.bytesize}\r\n" + resp << "Server: plum/#{Plum::VERSION}\r\n" + resp << "\r\n" + resp << data + + sock.write(resp) rescue puts $! puts $!.backtrace diff --git a/lib/plum/errors.rb b/lib/plum/errors.rb index 5b4b565..2770b27 100644 --- a/lib/plum/errors.rb +++ b/lib/plum/errors.rb @@ -1,5 +1,6 @@ module Plum class Error < StandardError; end + class LegacyHTTPError < Error; end class HPACKError < Error; end class HTTPError < Error ERROR_CODES = { diff --git a/lib/plum/http_connection.rb b/lib/plum/http_connection.rb index 4ffea73..b7ca046 100644 --- a/lib/plum/http_connection.rb +++ b/lib/plum/http_connection.rb @@ -35,8 +35,7 @@ module Plum settings != nil) switch_protocol(settings) else - respond_not_supported - close + raise LegacyHTTPError.new end } @@ -60,20 +59,6 @@ module Plum io.write(resp) end - def respond_not_supported - data = "Use modern web browser with HTTP/2 support." - - resp = "" - resp << "HTTP/1.1 505 HTTP Version Not Supported\r\n" - resp << "Content-Type: text/plain\r\n" - resp << "Content-Length: #{data.bytesize}\r\n" - resp << "Server: plum/#{Plum::VERSION}\r\n" - resp << "\r\n" - resp << data - - io.write(resp) - end - def process_first_request encoder = HPACK::Encoder.new(0, indexing: false) # don't pollute connection's HPACK context stream = new_stream(1) diff --git a/test/plum/test_http_connection.rb b/test/plum/test_http_connection.rb index 1560c96..fc451d0 100644 --- a/test/plum/test_http_connection.rb +++ b/test/plum/test_http_connection.rb @@ -55,7 +55,8 @@ class HTTPConnectionNegotiationTest < Minitest::Test "User-Agent: nya\r\n" << "Connection: close\r\n" << "\r\n" - con << req - assert(io.string.include?("HTTP/1.1 505 "), "Response is not HTTP/1.1 505: #{io.string}") + assert_raises(LegacyHTTPError) { + con << req + } end end |