Class: ICAPrb::Server::ResponseHeader

Inherits:
HTTP_Header
  • Object
show all
Defined in:
lib/icaprb/server/data_structures.rb

Overview

This class represents the Header of an HTTP response. It includes the headers sent by the web server as well as the status line

Instance Method Summary collapse

Methods inherited from HTTP_Header

#to_s

Constructor Details

#initialize(http_version, status_code) ⇒ ResponseHeader

Params:

http_version

is the version of http to use - usually 1.1

status_code

is the status code of the http protocol. For example 200 for OK



109
110
111
112
# File 'lib/icaprb/server/data_structures.rb', line 109

def initialize(http_version, status_code)
  @http_version = http_version
  @status_code = status_code
end

Instance Method Details

#<=>(other) ⇒ Object

The request header has to come first



121
122
123
124
125
126
127
128
129
130
# File 'lib/icaprb/server/data_structures.rb', line 121

def <=>(other)
  case other
    when RequestHeader
      1
    when ResponseHeader
      0
    else
      -1
  end
end

#request_lineObject

creates the response line for the request it will contain the http version, the status code and the status text from HTTP_STATUS_CODES



116
117
118
# File 'lib/icaprb/server/data_structures.rb', line 116

def request_line
  "HTTP/#{@http_version} #{@status_code} #{HTTP_STATUS_CODES[@status_code]}\r\n"
end