File tree Expand file tree Collapse file tree 2 files changed +20
-12
lines changed Expand file tree Collapse file tree 2 files changed +20
-12
lines changed Original file line number Diff line number Diff line change @@ -198,7 +198,11 @@ def extract(keys)
198
198
# @parameter key [String] the header key.
199
199
# @parameter value [String] the header value to assign.
200
200
def add ( key , value )
201
- self [ key ] = value
201
+ if @indexed
202
+ merge_into ( @indexed , key . downcase , value )
203
+ end
204
+
205
+ @fields << [ key , value ]
202
206
end
203
207
204
208
# Set the specified header key to the specified value, replacing any existing header keys with the same name.
@@ -230,11 +234,8 @@ def merge(headers)
230
234
# @parameter key [String] The header key.
231
235
# @parameter value [String] The header value.
232
236
def []= key , value
233
- if @indexed
234
- merge_into ( @indexed , key . downcase , value )
235
- end
236
-
237
- @fields << [ key , value ]
237
+ # The value MUST be a string, so we convert it to a string to prevent errors later on.
238
+ self . add ( key , value . to_s )
238
239
end
239
240
240
241
# The policy for various headers, including how they are merged and normalized.
Original file line number Diff line number Diff line change 167
167
end
168
168
169
169
with "#[]=" do
170
- it "can add field" do
170
+ it "can add field with a String value" do
171
+ headers [ "Content-Length" ] = "1"
172
+
173
+ expect ( headers . fields . last ) . to be == [ "Content-Length" , "1" ]
174
+ expect ( headers [ "content-length" ] ) . to be == "1"
175
+ end
176
+
177
+ it "can add field with an Integer value" do
171
178
headers [ "Content-Length" ] = 1
172
179
173
- expect ( headers . fields . last ) . to be == [ "Content-Length" , 1 ]
174
- expect ( headers [ "content-length" ] ) . to be == 1
180
+ expect ( headers . fields . last ) . to be == [ "Content-Length" , "1" ]
181
+ expect ( headers [ "content-length" ] ) . to be == "1"
175
182
end
176
183
177
184
it "can add field with indexed hash" do
178
185
expect ( headers . to_h ) . not . to be ( :empty? )
179
186
180
- headers [ "Content-Length" ] = 1
181
- expect ( headers [ "content-length" ] ) . to be == 1
187
+ headers [ "Content-Length" ] = "1"
188
+ expect ( headers [ "content-length" ] ) . to be == "1"
182
189
end
183
190
end
184
191
241
248
it "can merge content-length" do
242
249
headers . merge! ( "content-length" => 2 )
243
250
244
- expect ( headers [ "content-length" ] ) . to be == 2
251
+ expect ( headers [ "content-length" ] ) . to be == "2"
245
252
end
246
253
end
247
254
You can’t perform that action at this time.
0 commit comments