Class: M2R::Request

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HTTP::Close

#close?

Methods included from Upload

#body_io, #free!, #upload?, #upload_done?, #upload_path, #upload_start?

Methods included from Base

#body_io, #free!

Constructor Details

#initialize(sender, conn_id, path, http_headers, mongrel_headers, body) ⇒ Request

Returns a new instance of Request.



42
43
44
45
46
47
48
49
50
# File 'lib/m2r/request.rb', line 42

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

#bodyString (readonly)

Returns HTTP Body of request.



34
35
36
# File 'lib/m2r/request.rb', line 34

def body
  @body
end

#conn_idString (readonly)

Returns Mongrel2 connection id sending this request.



28
29
30
# File 'lib/m2r/request.rb', line 28

def conn_id
  @conn_id
end

#pathString (readonly)

Returns HTTP Path of request.



31
32
33
# File 'lib/m2r/request.rb', line 31

def path
  @path
end

#senderString (readonly)

Returns UUID of mongrel2 origin instance.



25
26
27
# File 'lib/m2r/request.rb', line 25

def sender
  @sender
end

Class Method Details

.parse(msg) ⇒ Request

Deprecated.

Parse Mongrel2 request received via ZMQ message



60
61
62
# File 'lib/m2r/request.rb', line 60

def self.parse(msg)
  Parser.new.parse(msg)
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.



96
97
98
# File 'lib/m2r/request.rb', line 96

def disconnect?
  json? and @data['type'] == 'disconnect'
end

#headersM2R::Headers

Returns HTTP headers.



65
66
67
# File 'lib/m2r/request.rb', line 65

def headers
  @http_headers
end

#http_versionObject



89
90
91
# File 'lib/m2r/request.rb', line 89

def http_version
  @mongrel_headers['version']
end

#methodString

Returns HTTP method.



75
76
77
# File 'lib/m2r/request.rb', line 75

def method
  @mongrel_headers['method']
end

#patternString

Returns Mongrel2 pattern used to match this request.



70
71
72
# File 'lib/m2r/request.rb', line 70

def pattern
  @mongrel_headers['pattern']
end

#queryString

Returns Request query string.



80
81
82
# File 'lib/m2r/request.rb', line 80

def query
  @mongrel_headers['query']
end

#schemeObject

return [String] URL scheme



85
86
87
# File 'lib/m2r/request.rb', line 85

def scheme
  @mongrel_headers['url_scheme'] || mongrel17_scheme
end