diff --git a/lib/pitchfork/http_parser.rb b/lib/pitchfork/http_parser.rb index 705d181a..6f0fc4c7 100644 --- a/lib/pitchfork/http_parser.rb +++ b/lib/pitchfork/http_parser.rb @@ -93,6 +93,9 @@ def read(socket) e['pitchfork.socket'] = socket e['rack.hijack'] = self + # We don't support connection upgrade: + e.delete('HTTP_UPGRADE') + e.merge!(DEFAULTS) end diff --git a/test/integration/test_http_basic.rb b/test/integration/test_http_basic.rb index d5a65f43..2cbafc4f 100644 --- a/test/integration/test_http_basic.rb +++ b/test/integration/test_http_basic.rb @@ -136,4 +136,28 @@ def test_write_on_close assert_clean_shutdown(pid) end + + def test_http_upgrade + addr, port = unused_port + + pid = spawn_server(app: File.join(ROOT, "test/integration/upgrade.ru"), config: <<~CONFIG) + listen "#{addr}:#{port}" + worker_processes 1 + CONFIG + + assert_healthy("http://#{addr}:#{port}") + + Net::HTTP.start(addr, port) do |http| + request = Net::HTTP::Get.new("/") + request["Connection"] = "Upgrade" + request["Upgrade"] = "websocket" + + # It should not be connection upgrade: + response = http.request(request) + assert_equal "200", response.code + assert_equal "Normal response", response.body + end + + assert_clean_shutdown(pid) + end end diff --git a/test/integration/upgrade.ru b/test/integration/upgrade.ru new file mode 100644 index 00000000..edf305f5 --- /dev/null +++ b/test/integration/upgrade.ru @@ -0,0 +1,8 @@ +# frozen_string_literal: true +run lambda { |env| + if env['HTTP_UPGRADE'] + [404, {}, ["Upgrade not supported"]] + else + [200, {}, ["Normal response"]] + end +}