Class: Rig::HTTPHeader

Inherits:
Hash
  • Object
show all
Defined in:
lib/rig/http_header.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ HTTPHeader

Returns a new instance of HTTPHeader.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rig/http_header.rb', line 4

def initialize options
  http_method = options[:http_method]
  path        = options[:path]

  header = {
    ""                => "#{http_method} #{path} HTTP/1.1",
    "Host"            => options[:host],
    "Origin"          => "localhost",
    "Content-Length"  => options[:content_length],
    "Content-Type"    => options[:content_type]
  }.merge(
    (options[:custom_header] || {})
  ).merge(
    "Connection"      => "close"
  )

  merge!( header )
end

Instance Method Details

#to_sObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rig/http_header.rb', line 23

def to_s
  header_string = map do |field_name, value|
    if field_name == ""
      value
    else
      "#{field_name}: #{value}"
    end
  end

  header_string.join(CRLF) + CRLF + CRLF
end