Skip to content

Commit 5ed9fd6

Browse files
committed
Save reason phrase in Protocol::HTTP1::Response
Save away the raw reason phrase provided by the server. This is of limited niche value, as the reason phrase seems to be _mostly_ unused/ignored. One example of where it's needed: The [Proxmox VE API](https://pve.proxmox.com/wiki/Proxmox_VE_API) ships error reason strings back using the HTTP reason phrase. Without this side-channel, error status is 100% opaque/unavailable.
1 parent 26a52f0 commit 5ed9fd6

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/async/http/protocol/http1/response.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ def self.read(connection, request)
1818

1919
UPGRADE = 'upgrade'
2020

21-
# @param reason [String] HTTP response line reason, ignored.
21+
attr_reader :reason
22+
23+
# @param reason [String] HTTP response line reason phrase
2224
def initialize(connection, version, status, reason, headers, body)
2325
@connection = connection
26+
@reason = reason
2427

2528
protocol = headers.delete(UPGRADE)
2629

@@ -30,7 +33,7 @@ def initialize(connection, version, status, reason, headers, body)
3033
def connection
3134
@connection
3235
end
33-
36+
3437
def hijack?
3538
@body.nil?
3639
end

test/async/http/protocol/http11.rb

+7
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def around
4646
expect(response).to be(:success?)
4747
expect(response.version).to be == "HTTP/1.1"
4848
expect(response.body).to be(:empty?)
49+
expect(response.reason).to be == "OK"
4950

5051
response.read
5152
end
@@ -74,6 +75,12 @@ def around
7475

7576
expect(response.read).to be == "Hello World!"
7677
end
78+
79+
it "has access to the http reason phrase" do
80+
response = client.head("/")
81+
82+
expect(response.reason).to be == "It worked!"
83+
end
7784
end
7885
end
7986
end

0 commit comments

Comments
 (0)