Class: RightSpeed::Handler::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/right_speed/handler.rb

Constant Summary collapse

STATUS_MESSAGE_MAP =
{
  200 => "OK",
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_version:, status_code:, headers:, body:) ⇒ Response

Returns a new instance of Response.



114
115
116
117
118
119
120
# File 'lib/right_speed/handler.rb', line 114

def initialize(http_version:, status_code:, headers:, body:)
  @http_version = http_version
  @status_code = status_code
  @status_message = STATUS_MESSAGE_MAP.fetch(status_code, "Unknown")
  @headers = headers
  @body = body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



112
113
114
# File 'lib/right_speed/handler.rb', line 112

def body
  @body
end

Instance Method Details

#headersObject



126
127
128
# File 'lib/right_speed/handler.rb', line 126

def headers
  @headers.map{|key, value| "#{key}: #{value}\r\n" }.join + "\r\n"
end

#statusObject



122
123
124
# File 'lib/right_speed/handler.rb', line 122

def status
  "#{@http_version} #{@status_code} #{@status_message}\r\n"
end