class Knod::Request

Attributes

headers[R]
request_line[R]
socket[R]

Public Class Methods

new(socket) click to toggle source
# File lib/knod/request.rb, line 5
def initialize(socket)
  @socket = socket
  @request_line = socket.gets
  parse_request
end

Public Instance Methods

body() click to toggle source
# File lib/knod/request.rb, line 38
def body
  @body ||= socket.read(content_length)
end
content_length() click to toggle source
# File lib/knod/request.rb, line 22
def content_length
  headers['Content-Length'].to_i
end
content_type() click to toggle source
# File lib/knod/request.rb, line 26
def content_type
  headers['Content-Type']
end
method() click to toggle source
# File lib/knod/request.rb, line 34
def method
  @verb ||= request_line.split.first.upcase
end
parse_request() click to toggle source
# File lib/knod/request.rb, line 11
def parse_request
  headers = {}
  loop do
    line = socket.gets
    break if line == "\r\n"
    name, value = line.strip.split(': ')
    headers[name] = value
  end
  @headers = headers
end
uri() click to toggle source
# File lib/knod/request.rb, line 30
def uri
  @uri ||= request_line.split[1]
end