Class: EmmyHttp::Server::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/emmy_http/server/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/emmy_http/server/parser.rb', line 13

def initialize
  @http_parser = HTTP::Parser.new
  @http_parser.header_value_type = :mixed
  @http_parser.on_headers_complete = proc do
    head!(http_parser.headers, http_parser)
    stop ? :stop : (no_body ? :reset : nil)
  end
  @http_parser.on_body = proc do |chunk|
    body!(chunk)
  end
  @http_parser.on_message_complete = proc do
    complete!
  end
end

Instance Attribute Details

#http_parserObject

Returns the value of attribute http_parser.



9
10
11
# File 'lib/emmy_http/server/parser.rb', line 9

def http_parser
  @http_parser
end

#no_bodyObject

Returns the value of attribute no_body.



11
12
13
# File 'lib/emmy_http/server/parser.rb', line 11

def no_body
  @no_body
end

#stopObject

Returns the value of attribute stop.



10
11
12
# File 'lib/emmy_http/server/parser.rb', line 10

def stop
  @stop
end

Instance Method Details

#<<(data) ⇒ Object



28
29
30
31
32
# File 'lib/emmy_http/server/parser.rb', line 28

def <<(data)
  @http_parser << data
rescue HTTP::Parser::Error => e
  raise EmmyHttp::ParserError, e.to_s
end

#headersObject



42
43
44
# File 'lib/emmy_http/server/parser.rb', line 42

def headers
  @http_parser.headers
end

#http_methodObject



38
39
40
# File 'lib/emmy_http/server/parser.rb', line 38

def http_method
  @http_parser.http_method
end

#http_versionObject



46
47
48
# File 'lib/emmy_http/server/parser.rb', line 46

def http_version
  @http_parser.http_version
end

#request_urlObject



50
51
52
# File 'lib/emmy_http/server/parser.rb', line 50

def request_url
  @http_parser.request_url
end

#reset!Object



54
55
56
# File 'lib/emmy_http/server/parser.rb', line 54

def reset!
  @http_parser.reset!
end

#status_codeObject



34
35
36
# File 'lib/emmy_http/server/parser.rb', line 34

def status_code
  @http_parser.status_code
end