Class: M2R::Request
- Inherits:
-
Object
- Object
- M2R::Request
- Includes:
- Base, HTTP::Close, Upload
- Defined in:
- lib/m2r/request.rb
Overview
Abstraction over Mongrel 2 request
Constant Summary collapse
- TRUE_STRINGS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Set.new(%w(true yes on 1).map(&:freeze)).freeze
- MONGREL2_BASE_HEADERS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Set.new(%w(pattern method path query url_scheme version).map(&:upcase).map(&:freeze)).freeze
- MONGREL2_UPLOAD_HEADERS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Set.new(%w(x-mongrel2-upload-start x-mongrel2-upload-done).map(&:downcase).map(&:freeze)).freeze
- MONGREL2_HEADERS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
(MONGREL2_BASE_HEADERS + MONGREL2_UPLOAD_HEADERS).freeze
Instance Attribute Summary collapse
-
#body ⇒ String
readonly
HTTP Body of request.
-
#conn_id ⇒ String
readonly
Mongrel2 connection id sending this request.
-
#path ⇒ String
readonly
HTTP Path of request.
-
#sender ⇒ String
readonly
UUID of mongrel2 origin instance.
Class Method Summary collapse
-
.parse(msg) ⇒ Request
Parse Mongrel2 request received via ZMQ message.
Instance Method Summary collapse
-
#disconnect? ⇒ true, false
Internal mongrel2 message to handler issued when message delivery is not possible because the client already disconnected and there is no connection with such #conn_id.
-
#headers ⇒ M2R::Headers
HTTP headers.
- #http_version ⇒ Object
-
#initialize(sender, conn_id, path, http_headers, mongrel_headers, body) ⇒ Request
constructor
A new instance of Request.
-
#method ⇒ String
HTTP method.
-
#pattern ⇒ String
Mongrel2 pattern used to match this request.
-
#query ⇒ String
Request query string.
-
#scheme ⇒ Object
return [String] URL scheme.
Methods included from HTTP::Close
Methods included from Upload
#body_io, #free!, #upload?, #upload_done?, #upload_path, #upload_start?
Methods included from Base
Constructor Details
#initialize(sender, conn_id, path, http_headers, mongrel_headers, body) ⇒ Request
Returns a new instance of Request.
43 44 45 46 47 48 49 50 51 |
# File 'lib/m2r/request.rb', line 43 def initialize(sender, conn_id, path, http_headers, mongrel_headers, body) @sender = sender @conn_id = conn_id @path = path @http_headers = http_headers @mongrel_headers = mongrel_headers @body = body @data = MultiJson.load(@body) if json? end |
Instance Attribute Details
#body ⇒ String (readonly)
Returns HTTP Body of request.
35 36 37 |
# File 'lib/m2r/request.rb', line 35 def body @body end |
#conn_id ⇒ String (readonly)
Returns Mongrel2 connection id sending this request.
29 30 31 |
# File 'lib/m2r/request.rb', line 29 def conn_id @conn_id end |
#path ⇒ String (readonly)
Returns HTTP Path of request.
32 33 34 |
# File 'lib/m2r/request.rb', line 32 def path @path end |
#sender ⇒ String (readonly)
Returns UUID of mongrel2 origin instance.
26 27 28 |
# File 'lib/m2r/request.rb', line 26 def sender @sender end |
Class Method Details
.parse(msg) ⇒ Request
Parse Mongrel2 request received via ZMQ message
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/m2r/request.rb', line 60 def self.parse(msg) sender, conn_id, path, rest = msg.split(' ', 4) headers, rest = TNetstring.parse(rest) body, _ = TNetstring.parse(rest) headers = MultiJson.load(headers) headers, mong = split_headers(headers) headers = Headers.new headers, true mong = Headers.new mong, true self.new(sender, conn_id, path, headers, mong, body) end |
Instance Method Details
#disconnect? ⇒ true, false
Returns Internal mongrel2 message to handler issued when message delivery is not possible because the client already disconnected and there is no connection with such #conn_id.
104 105 106 |
# File 'lib/m2r/request.rb', line 104 def disconnect? json? and @data['type'] == 'disconnect' end |
#headers ⇒ M2R::Headers
Returns HTTP headers.
73 74 75 |
# File 'lib/m2r/request.rb', line 73 def headers @http_headers end |
#http_version ⇒ Object
97 98 99 |
# File 'lib/m2r/request.rb', line 97 def http_version @mongrel_headers['version'] end |
#method ⇒ String
Returns HTTP method.
83 84 85 |
# File 'lib/m2r/request.rb', line 83 def method @mongrel_headers['method'] end |
#pattern ⇒ String
Returns Mongrel2 pattern used to match this request.
78 79 80 |
# File 'lib/m2r/request.rb', line 78 def pattern @mongrel_headers['pattern'] end |
#query ⇒ String
Returns Request query string.
88 89 90 |
# File 'lib/m2r/request.rb', line 88 def query @mongrel_headers['query'] end |
#scheme ⇒ Object
return [String] URL scheme
93 94 95 |
# File 'lib/m2r/request.rb', line 93 def scheme @mongrel_headers['url_scheme'] || mongrel17_scheme end |