Class: Reel::Request::Parser
- Inherits:
-
Object
- Object
- Reel::Request::Parser
- Includes:
- HTTPVersionsMixin
- Defined in:
- lib/reel/request/parser.rb
Constant Summary
Constants included from HTTPVersionsMixin
HTTPVersionsMixin::DEFAULT_HTTP_VERSION, HTTPVersionsMixin::HTTP_VERSION_1_0, HTTPVersionsMixin::HTTP_VERSION_1_1
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Instance Method Summary collapse
- #add(data) ⇒ Object (also: #<<)
- #current_request ⇒ Object
- #http_method ⇒ Object
- #http_version ⇒ Object
-
#initialize(connection) ⇒ Parser
constructor
A new instance of Parser.
-
#on_body(chunk) ⇒ Object
Send body directly to Reel::Response to be buffered.
-
#on_headers_complete(headers) ⇒ Object
HTTP::Parser callbacks.
-
#on_message_complete ⇒ Object
Mark current request as complete, set this as ready to respond.
- #readpartial(size = @buffer_size) ⇒ Object
- #reset ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(connection) ⇒ Parser
Returns a new instance of Parser.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/reel/request/parser.rb', line 7 def initialize(connection) @parser = HTTP::Parser.new(self) @connection = connection @socket = connection.socket @buffer_size = connection.buffer_size @currently_reading = @currently_responding = nil @pending_reads = [] @pending_responses = [] reset end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
5 6 7 |
# File 'lib/reel/request/parser.rb', line 5 def connection @connection end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
5 6 7 |
# File 'lib/reel/request/parser.rb', line 5 def socket @socket end |
Instance Method Details
#add(data) ⇒ Object Also known as: <<
19 20 21 |
# File 'lib/reel/request/parser.rb', line 19 def add(data) @parser << data end |
#current_request ⇒ Object
37 38 39 40 41 42 |
# File 'lib/reel/request/parser.rb', line 37 def current_request until @currently_responding || @currently_reading readpartial end @currently_responding || @currently_reading end |
#http_method ⇒ Object
24 25 26 |
# File 'lib/reel/request/parser.rb', line 24 def http_method @parser.http_method end |
#http_version ⇒ Object
28 29 30 31 |
# File 'lib/reel/request/parser.rb', line 28 def http_version # TODO: add extra HTTP_VERSION handler when HTTP/1.2 released @parser.http_version[1] == 1 ? HTTP_VERSION_1_1 : HTTP_VERSION_1_0 end |
#on_body(chunk) ⇒ Object
Send body directly to Reel::Response to be buffered.
64 65 66 |
# File 'lib/reel/request/parser.rb', line 64 def on_body(chunk) @currently_reading.fill_buffer(chunk) end |
#on_headers_complete(headers) ⇒ Object
HTTP::Parser callbacks
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/reel/request/parser.rb', line 52 def on_headers_complete(headers) info = Info.new(http_method, url, http_version, headers) req = Request.new(info, connection) if @currently_reading @pending_reads << req else @currently_reading = req end end |
#on_message_complete ⇒ Object
Mark current request as complete, set this as ready to respond.
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/reel/request/parser.rb', line 69 def @currently_reading.finish_reading! if @currently_reading.is_a?(Request) if @currently_responding @pending_responses << @currently_reading else @currently_responding = @currently_reading end @currently_reading = @pending_reads.shift end |
#readpartial(size = @buffer_size) ⇒ Object
44 45 46 47 |
# File 'lib/reel/request/parser.rb', line 44 def readpartial(size = @buffer_size) bytes = @socket.readpartial(size) @parser << bytes end |
#reset ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/reel/request/parser.rb', line 81 def reset popped = @currently_responding if req = @pending_responses.shift @currently_responding = req elsif @currently_responding @currently_responding = nil end popped end |
#url ⇒ Object
33 34 35 |
# File 'lib/reel/request/parser.rb', line 33 def url @parser.request_url end |