Class: Headers
Overview
Represents headers from an HTTP request or response. Used internally by HTTP backends for processing headers.
Class Method Summary collapse
-
.parse(chunk) ⇒ Object
Parse a single header line into its key and value.
Instance Method Summary collapse
-
#initialize ⇒ Headers
constructor
A new instance of Headers.
-
#parse(chunk) ⇒ Object
Parses a header line and adds it to the header collection.
Methods included from Net::HTTPHeader
Constructor Details
#initialize ⇒ Headers
Returns a new instance of Headers.
367 368 369 |
# File 'lib/zephyr.rb', line 367 def initialize initialize_http_header({}) end |
Class Method Details
.parse(chunk) ⇒ Object
Parse a single header line into its key and value
373 374 375 376 377 378 379 |
# File 'lib/zephyr.rb', line 373 def self.parse(chunk) line = chunk.strip # thanks Net::HTTPResponse return [nil,nil] if chunk =~ /\AHTTP(?:\/(\d+\.\d+))?\s+(\d\d\d)\s*(.*)\z/in m = /\A([^:]+):\s*/.match(line) [m[1], m.post_match] rescue [nil, nil] end |
Instance Method Details
#parse(chunk) ⇒ Object
Parses a header line and adds it to the header collection
383 384 385 386 |
# File 'lib/zephyr.rb', line 383 def parse(chunk) key, value = self.class.parse(chunk) add_field(key, value) if key && value end |