Class: Mongrel2::Request
- Inherits:
-
Object
- Object
- Mongrel2::Request
- Defined in:
- lib/mongrel2/request.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#conn_id ⇒ Object
readonly
Returns the value of attribute conn_id.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Class Method Summary collapse
Instance Method Summary collapse
- #close? ⇒ Boolean
- #disconnect? ⇒ Boolean
-
#initialize(uuid, conn_id, path, headers, body) ⇒ Request
constructor
A new instance of Request.
Constructor Details
#initialize(uuid, conn_id, path, headers, body) ⇒ Request
Returns a new instance of Request.
27 28 29 30 |
# File 'lib/mongrel2/request.rb', line 27 def initialize(uuid, conn_id, path, headers, body) @uuid, @conn_id, @path, @headers, @body = uuid, conn_id, path, headers, body @data = headers['METHOD'] == 'JSON' ? Mongrel2::JSON.parse(body) : {} end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
5 6 7 |
# File 'lib/mongrel2/request.rb', line 5 def body @body end |
#conn_id ⇒ Object (readonly)
Returns the value of attribute conn_id.
5 6 7 |
# File 'lib/mongrel2/request.rb', line 5 def conn_id @conn_id end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
5 6 7 |
# File 'lib/mongrel2/request.rb', line 5 def headers @headers end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/mongrel2/request.rb', line 5 def path @path end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
5 6 7 |
# File 'lib/mongrel2/request.rb', line 5 def uuid @uuid end |
Class Method Details
.parse(msg) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/mongrel2/request.rb', line 8 def parse(msg) # UUID CONN_ID PATH SIZE:HEADERS,SIZE:BODY, uuid, conn_id, path, rest = msg.split(' ', 4) headers, rest = parse_netstring(rest) body, _ = parse_netstring(rest) headers = Mongrel2::JSON.parse(headers) new(uuid, conn_id, path, headers, body) end |
.parse_netstring(ns) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/mongrel2/request.rb', line 17 def parse_netstring(ns) # SIZE:HEADERS, len, rest = ns.split(':', 2) len = len.to_i raise "Netstring did not end in ','" unless rest[len].chr == ',' [rest[0, len], rest[(len + 1)..-1]] end |
Instance Method Details
#close? ⇒ Boolean
36 37 38 |
# File 'lib/mongrel2/request.rb', line 36 def close? headers['connection'] == 'close' || headers['VERSION'] == 'HTTP/1.0' end |
#disconnect? ⇒ Boolean
32 33 34 |
# File 'lib/mongrel2/request.rb', line 32 def disconnect? headers['METHOD'] == 'JSON' && @data['type'] == 'disconnect' end |