@@ -20,8 +20,13 @@ def response
20
20
21
21
expect ( response . status ) . to be ( 200 )
22
22
expect ( response . body . to_s ) . to be_empty
23
- expect ( headers ) . to include ( [ "Content-Type" , "application/octet-stream; charset=utf-8" ] )
24
- expect ( headers ) . to include ( %w[ Content-Length 5 ] )
23
+ expect ( headers ) . to include ( [ rack_header ( "Content-Type" ) , "application/octet-stream; charset=utf-8" ] )
24
+
25
+ # In Rack 2, the Content-Length header is inferred from the body, even for HEAD requests.
26
+ # In Rack 3, the Content-Length header is no longer automatically set.
27
+ content_length = Hanami ::Action . rack_3? ? "0" : "5"
28
+
29
+ expect ( headers ) . to include ( [ rack_header ( "Content-Length" ) , content_length ] )
25
30
end
26
31
27
32
it "allows to bypass restriction on custom headers" do
@@ -31,11 +36,11 @@ def response
31
36
expect ( response . body ) . to eq ( "" )
32
37
33
38
headers = response . headers . to_a
34
- expect ( headers ) . to include ( [ "Last-Modified" , "Fri, 27 Nov 2015 13:32:36 GMT" ] )
35
- expect ( headers ) . to include ( %w[ X-Rate-Limit 4000 ] )
39
+ expect ( headers ) . to include ( [ rack_header ( "Last-Modified" ) , "Fri, 27 Nov 2015 13:32:36 GMT" ] )
40
+ expect ( headers ) . to include ( [ rack_header ( " X-Rate-Limit" ) , " 4000" ] )
36
41
37
- expect ( headers ) . to_not include ( %w[ X-No-Pass true ] )
38
- expect ( headers ) . to_not include ( [ "Content-Type" , "application/octet-stream; charset=utf-8" ] )
42
+ expect ( headers ) . to_not include ( [ rack_header ( " X-No-Pass" ) , " true" ] )
43
+ expect ( headers ) . to_not include ( [ rack_header ( "Content-Type" ) , "application/octet-stream; charset=utf-8" ] )
39
44
end
40
45
41
46
HTTP_TEST_STATUSES_WITHOUT_BODY . each do |code |
@@ -46,93 +51,93 @@ def response
46
51
47
52
expect ( response . status ) . to be ( code )
48
53
expect ( response . body ) . to eq ( "" )
49
- expect ( response . headers . to_a ) . to_not include ( %w[ X-Frame-Options DENY ] )
54
+ expect ( response . headers . to_a ) . to_not include ( [ rack_header ( " X-Frame-Options" ) , " DENY" ] )
50
55
end
51
56
52
57
it "doesn't send Content-Length header" do
53
58
get "/code/#{ code } "
54
59
55
60
expect ( response . status ) . to be ( code )
56
- expect ( response . headers ) . to_not have_key ( "Content-Length" )
61
+ expect ( response . headers ) . to_not have_key ( rack_header ( "Content-Length" ) )
57
62
end
58
63
else
59
64
it "does send body and default headers" do
60
65
get "/code/#{ code } "
61
66
62
67
expect ( response . status ) . to be ( code )
63
68
expect ( response . body ) . to_not be_empty
64
- expect ( response . headers . to_a ) . to_not include ( %w[ X-Frame-Options DENY ] )
69
+ expect ( response . headers . to_a ) . to_not include ( [ rack_header ( " X-Frame-Options" ) , " DENY" ] )
65
70
end
66
71
67
72
it "does send Content-Length header" do
68
73
get "/code/#{ code } "
69
74
70
75
expect ( response . status ) . to be ( code )
71
- expect ( response . headers ) . to have_key ( "Content-Length" )
76
+ expect ( response . headers ) . to have_key ( rack_header ( "Content-Length" ) )
72
77
end
73
78
end
74
79
75
80
it "sends Allow header" do
76
81
get "/code/#{ code } "
77
82
78
- expect ( response . status ) . to be ( code )
79
- expect ( response . headers [ "Allow" ] ) . to eq ( "GET, HEAD" )
83
+ expect ( response . status ) . to be ( code )
84
+ expect ( response . headers [ rack_header ( "Allow" ) ] ) . to eq ( "GET, HEAD" )
80
85
end
81
86
82
87
it "sends Content-Encoding header" do
83
88
get "/code/#{ code } "
84
89
85
- expect ( response . status ) . to be ( code )
86
- expect ( response . headers [ "Content-Encoding" ] ) . to eq ( "identity" )
90
+ expect ( response . status ) . to be ( code )
91
+ expect ( response . headers [ rack_header ( "Content-Encoding" ) ] ) . to eq ( "identity" )
87
92
end
88
93
89
94
it "sends Content-Language header" do
90
95
get "/code/#{ code } "
91
96
92
- expect ( response . status ) . to be ( code )
93
- expect ( response . headers [ "Content-Language" ] ) . to eq ( "en" )
97
+ expect ( response . status ) . to be ( code )
98
+ expect ( response . headers [ rack_header ( "Content-Language" ) ] ) . to eq ( "en" )
94
99
end
95
100
96
101
it "doesn't send Content-Length header" do
97
102
get "/code/#{ code } "
98
103
99
104
expect ( response . status ) . to be ( code )
100
- expect ( response . headers . keys ) . to_not include ( "Content-Length" )
105
+ expect ( response . headers . keys ) . to_not include ( rack_header ( "Content-Length" ) )
101
106
end
102
107
103
108
it "doesn't send Content-Type header" do
104
109
get "/code/#{ code } "
105
110
106
111
expect ( response . status ) . to be ( code )
107
- expect ( response . headers . keys ) . to_not include ( "Content-Type" )
112
+ expect ( response . headers . keys ) . to_not include ( rack_header ( "Content-Type" ) )
108
113
end
109
114
110
115
it "sends Content-Location header" do
111
116
get "/code/#{ code } "
112
117
113
- expect ( response . status ) . to be ( code )
114
- expect ( response . headers [ "Content-Location" ] ) . to eq ( "relativeURI" )
118
+ expect ( response . status ) . to be ( code )
119
+ expect ( response . headers [ rack_header ( "Content-Location" ) ] ) . to eq ( "relativeURI" )
115
120
end
116
121
117
122
it "sends Content-MD5 header" do
118
123
get "/code/#{ code } "
119
124
120
- expect ( response . status ) . to be ( code )
121
- expect ( response . headers [ "Content-MD5" ] ) . to eq ( "c13367945d5d4c91047b3b50234aa7ab" )
125
+ expect ( response . status ) . to be ( code )
126
+ expect ( response . headers [ rack_header ( "Content-MD5" ) ] ) . to eq ( "c13367945d5d4c91047b3b50234aa7ab" )
122
127
end
123
128
124
129
it "sends Expires header" do
125
130
get "/code/#{ code } "
126
131
127
- expect ( response . status ) . to be ( code )
128
- expect ( response . headers [ "Expires" ] ) . to eq ( "Thu, 01 Dec 1994 16:00:00 GMT" )
132
+ expect ( response . status ) . to be ( code )
133
+ expect ( response . headers [ rack_header ( "Expires" ) ] ) . to eq ( "Thu, 01 Dec 1994 16:00:00 GMT" )
129
134
end
130
135
131
136
it "sends Last-Modified header" do
132
137
get "/code/#{ code } "
133
138
134
- expect ( response . status ) . to be ( code )
135
- expect ( response . headers [ "Last-Modified" ] ) . to eq ( "Wed, 21 Jan 2015 11:32:10 GMT" )
139
+ expect ( response . status ) . to be ( code )
140
+ expect ( response . headers [ rack_header ( "Last-Modified" ) ] ) . to eq ( "Wed, 21 Jan 2015 11:32:10 GMT" )
136
141
end
137
142
end
138
143
end
0 commit comments