Skip to content

Commit bcaae82

Browse files
committed
Introduce explicit support for informational responses.
1 parent 6c50b9a commit bcaae82

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

lib/protocol/http/response.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ def continue?
3333
@status == 100
3434
end
3535

36+
def informational?
37+
@status and @status >= 100 && @status < 200
38+
end
39+
40+
def final?
41+
# 101 is effectively a final status.
42+
@status and @status >= 200 || @status == 101
43+
end
44+
3645
def ok?
3746
@status == 200
3847
end

test/protocol/http/response.rb

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,25 @@
1010
let(:headers) {Protocol::HTTP::Headers.new}
1111
let(:body) {nil}
1212

13+
InformationalResponse = Sus::Shared("informational response") do
14+
it "should be informational" do
15+
expect(response).to be(:informational?)
16+
end
17+
18+
it "should not be a failure" do
19+
expect(response).not.to be(:failure?)
20+
end
21+
end
22+
1323
SuccessfulResponse = Sus::Shared("successful response") do
1424
it "should be successful" do
1525
expect(response).to be(:success?)
1626
end
1727

28+
it "should not be informational" do
29+
expect(response).not.to be(:informational?)
30+
end
31+
1832
it "should not be a failure" do
1933
expect(response).not.to be(:failure?)
2034
end
@@ -25,6 +39,10 @@
2539
expect(response).to be(:redirection?)
2640
end
2741

42+
it "should not be informational" do
43+
expect(response).not.to be(:informational?)
44+
end
45+
2846
it "should not be a failure" do
2947
expect(response).not.to be(:failure?)
3048
end
@@ -35,6 +53,10 @@
3553
expect(response).not.to be(:success?)
3654
end
3755

56+
it "should not be informational" do
57+
expect(response).not.to be(:informational?)
58+
end
59+
3860
it "should be a failure" do
3961
expect(response).to be(:failure?)
4062
end
@@ -51,7 +73,38 @@
5173
expect(response).not.to be(:preserve_method?)
5274
end
5375
end
54-
76+
77+
with "100 Continue" do
78+
let(:response) {subject.new("HTTP/1.1", 100, headers)}
79+
80+
it "should have attributes" do
81+
expect(response).to have_attributes(
82+
version: be == "HTTP/1.1",
83+
status: be == 100,
84+
headers: be == headers,
85+
body: be == nil,
86+
protocol: be == nil
87+
)
88+
end
89+
90+
it_behaves_like InformationalResponse
91+
92+
it "should be a continue" do
93+
expect(response).to be(:continue?)
94+
end
95+
96+
it "should not be a failure" do
97+
expect(response).not.to be(:failure?)
98+
end
99+
100+
it "should have a String representation" do
101+
expect(response.to_s).to be == "100 HTTP/1.1"
102+
end
103+
104+
it "should have an Array representation" do
105+
expect(response.to_ary).to be == [100, headers, nil]
106+
end
107+
end
55108

56109
with "301 Moved Permanently" do
57110
let(:response) {subject.new("HTTP/1.1", 301, headers, body)}

0 commit comments

Comments
 (0)