Class: Kwipper::HttpParser

Inherits:
Object
  • Object
show all
Defined in:
lib/kwipper/http_parser.rb

Constant Summary collapse

HEADER_DELIMITER =
"\r\n"

Instance Method Summary collapse

Instance Method Details

#parse(raw_request) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/kwipper/http_parser.rb', line 5

def parse(raw_request)
  @first_line = raw_request.gets

  if @first_line.nil?
    raise Kwipper::EmptyRequest, 'could not get first line'
  else
    Request.new do |r|
      r.http_method = @first_line.split(' ').first
      r.path      = parse_path
      r.query     = parse_query
      r.headers   = parse_headers raw_request
      r.post_data = parse_query_string raw_request.read(r.content_length) if r.post_data?
    end
  end
end