You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Flatten trailer into the headers, returning a new instance of {Headers}.
82
92
defflatten
83
93
self.dup.flatten!
84
94
end
85
95
86
-
# An array of `[key, value]` pairs.
96
+
# @attribute [Array] An array of `[key, value]` pairs.
87
97
attr:fields
88
98
89
-
# @returns Whether there are any trailers.
99
+
# @returns [Boolean] Whether there are any trailers.
90
100
deftrailer?
91
101
@tail != nil
92
102
end
93
103
94
104
# Record the current headers, and prepare to add trailers.
95
105
#
96
-
# This method is typically used after headers are sent to capture any
97
-
# additional headers which should then be sent as trailers.
106
+
# This method is typically used after headers are sent to capture any additional headers which should then be sent as trailers.
98
107
#
99
-
# A sender that intends to generate one or more trailer fields in a
100
-
# message should generate a trailer header field in the header section of
101
-
# that message to indicate which fields might be present in the trailers.
108
+
# A sender that intends to generate one or more trailer fields in a message should generate a trailer header field in the header section of that message to indicate which fields might be present in the trailers.
102
109
#
103
110
# @parameter names [Array] The trailer header names which will be added later.
104
-
# @yields block {|name, value| ...} The trailer headers if any.
111
+
# @yields {|name, value| ...} the trailing headers if a block is given.
105
112
# @returns An enumerator which is suitable for iterating over trailers.
106
113
deftrailer!(&block)
107
114
@tail ||= @fields.size
@@ -118,6 +125,7 @@ def trailer(&block)
118
125
end
119
126
end
120
127
128
+
# Freeze the headers, and ensure the indexed hash is generated.
121
129
deffreeze
122
130
returniffrozen?
123
131
@@ -130,24 +138,35 @@ def freeze
130
138
super
131
139
end
132
140
141
+
# @returns [Boolean] Whether the headers are empty.
133
142
defempty?
134
143
@fields.empty?
135
144
end
136
145
146
+
# Enumerate all header keys and values.
147
+
#
148
+
# @yields {|key, value| ...}
149
+
# @parameter key [String] The header key.
150
+
# @parameter value [String] The header value.
137
151
defeach(&block)
138
152
@fields.each(&block)
139
153
end
140
154
155
+
# @returns [Boolean] Whether the headers include the specified key.
141
156
definclude?key
142
157
self[key] != nil
143
158
end
144
159
145
160
aliaskey?include?
146
161
162
+
# @returns [Array] All the keys of the headers.
147
163
defkeys
148
164
self.to_h.keys
149
165
end
150
166
167
+
# Extract the specified keys from the headers.
168
+
#
169
+
# @parameter keys [Array] The keys to extract.
151
170
defextract(keys)
152
171
deleted,@fields=@fields.partitiondo |field|
153
172
keys.include?(field.first.downcase)
@@ -164,21 +183,23 @@ def extract(keys)
164
183
165
184
# Add the specified header key value pair.
166
185
#
167
-
# @param key [String] the header key.
168
-
# @param value [String] the header value to assign.
186
+
# @parameter key [String] the header key.
187
+
# @parameter value [String] the header value to assign.
169
188
defadd(key,value)
170
189
self[key]=value
171
190
end
172
191
173
192
# Set the specified header key to the specified value, replacing any existing header keys with the same name.
174
-
# @param key [String] the header key to replace.
175
-
# @param value [String] the header value to assign.
193
+
#
194
+
# @parameter key [String] the header key to replace.
195
+
# @parameter value [String] the header value to assign.
176
196
defset(key,value)
177
197
# TODO This could be a bit more efficient:
178
198
self.delete(key)
179
199
self.add(key,value)
180
200
end
181
201
202
+
# Merge the headers into this instance.
182
203
defmerge!(headers)
183
204
headers.eachdo |key,value|
184
205
self[key]=value
@@ -187,13 +208,15 @@ def merge!(headers)
187
208
returnself
188
209
end
189
210
211
+
# Merge the headers into a new instance of {Headers}.
190
212
defmerge(headers)
191
213
self.dup.merge!(headers)
192
214
end
193
215
194
216
# Append the value to the given key. Some values can be appended multiple times, others can only be set once.
195
-
# @param key [String] The header key.
196
-
# @param value The header value.
217
+
#
218
+
# @parameter key [String] The header key.
219
+
# @parameter value [String] The header value.
197
220
def []= key,value
198
221
if@indexed
199
222
merge_into(@indexed,key.downcase,value)
@@ -202,8 +225,9 @@ def []= key, value
202
225
@fields << [key,value]
203
226
end
204
227
228
+
# The policy for various headers, including how they are merged and normalized.
205
229
POLICY={
206
-
# Headers which may only be specified once.
230
+
# Headers which may only be specified once:
207
231
"content-type"=>false,
208
232
"content-disposition"=>false,
209
233
"content-length"=>false,
@@ -251,7 +275,10 @@ def []= key, value
251
275
"if-unmodified-since"=>Header::Date,
252
276
}.tap{|hash| hash.default=Split}
253
277
254
-
# Delete all headers with the given key, and return the merged value.
278
+
# Delete all header values for the given key, and return the merged value.
0 commit comments