Skip to content

Commit c73e0b4

Browse files
committed
Don't advertise support for non-working connection upgrade.
1 parent 06b6d44 commit c73e0b4

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

lib/pitchfork/http_parser.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ def read(socket)
9393
e['pitchfork.socket'] = socket
9494
e['rack.hijack'] = self
9595

96+
# We don't support connection upgrade:
97+
e.delete('HTTP_UPGRADE')
98+
9699
e.merge!(DEFAULTS)
97100
end
98101

test/integration/test_http_basic.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,28 @@ def test_write_on_close
136136

137137
assert_clean_shutdown(pid)
138138
end
139+
140+
def test_http_upgrade
141+
addr, port = unused_port
142+
143+
pid = spawn_server(app: File.join(ROOT, "test/integration/upgrade.ru"), config: <<~CONFIG)
144+
listen "#{addr}:#{port}"
145+
worker_processes 1
146+
CONFIG
147+
148+
assert_healthy("http://#{addr}:#{port}")
149+
150+
Net::HTTP.start(addr, port) do |http|
151+
request = Net::HTTP::Get.new("/")
152+
request["Connection"] = "Upgrade"
153+
request["Upgrade"] = "websocket"
154+
155+
# It should not be connection upgrade:
156+
response = http.request(request)
157+
assert_equal "200", response.code
158+
assert_equal "Normal response", response.body
159+
end
160+
161+
assert_clean_shutdown(pid)
162+
end
139163
end

test/integration/upgrade.ru

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
run lambda { |env|
3+
if env['HTTP_UPGRADE']
4+
[404, {}, ["Upgrade not supported"]]
5+
else
6+
[200, {}, ["Normal response"]]
7+
end
8+
}

0 commit comments

Comments
 (0)