Class: Headers

Inherits:
Object
  • Object
show all
Includes:
Net::HTTPHeader
Defined in:
lib/zephyr.rb

Overview

Represents headers from an HTTP request or response. Used internally by HTTP backends for processing headers.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Net::HTTPHeader

#each_capitalized

Constructor Details

#initializeHeaders

Returns a new instance of Headers.



372
373
374
# File 'lib/zephyr.rb', line 372

def initialize
  initialize_http_header({})
end

Class Method Details

.parse(chunk) ⇒ Object

Parse a single header line into its key and value

Parameters:

  • chunk (String)

    a single header line



378
379
380
381
382
383
384
# File 'lib/zephyr.rb', line 378

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

Parameters:

  • chunk (String)

    a single header line



388
389
390
391
# File 'lib/zephyr.rb', line 388

def parse(chunk)
  key, value = self.class.parse(chunk)
  add_field(key, value) if key && value
end