320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
|
# File 'lib/gems/rack-0.9.1/lib/rack/lint.rb', line 320
def ()
assert("headers object should respond to #each, but doesn't (got #{header.class} as headers)") {
.respond_to? :each
}
.each { |key, value|
assert("header key must be a string, was #{key.class}") {
key.instance_of? String
}
assert("header must not contain Status") { key.downcase != "status" }
assert("header names must not contain : or \\n") { key !~ /[:\n]/ }
assert("header names must not end in - or _") { key !~ /[-_]\z/ }
assert("invalid header name: #{key}") { key =~ /\A[a-zA-Z][a-zA-Z0-9_-]*\z/ }
assert("header values must respond to #each, but the value of " +
"'#{key}' doesn't (is #{value.class})") { value.respond_to? :each }
value.each { |item|
assert("header values must consist of Strings, but '#{key}' also contains a #{item.class}") {
item.instance_of?(String)
}
assert("invalid header value #{key}: #{item.inspect}") {
item !~ /[\000-\037]/
}
}
}
end
|