Class: Doze::Request
- Inherits:
-
Rack::Request
- Object
- Rack::Request
- Doze::Request
- Defined in:
- lib/doze/request.rb
Overview
Some helpers for Rack::Request
Constant Summary collapse
- EXTENSION_REGEXP =
/\.([a-z0-9\-_]+)$/
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
Instance Method Summary collapse
- #entity ⇒ Object
- #extension ⇒ Object
- #get_or_head? ⇒ Boolean
-
#initialize(app, env) ⇒ Request
constructor
A new instance of Request.
- #media_type ⇒ Object
-
#negotiator(ignore_unacceptable_accepts = false) ⇒ Object
Makes a Doze::Negotiator to do content negotiation on behalf of this request.
-
#normalized_request_method ⇒ Object
this delibarately ignores the HEAD vs GET distinction; use head? to check.
- #options? ⇒ Boolean
-
#raw_path_info ⇒ Object
At this stage, we only care that the servlet spec says PATH_INFO is decoded so special case it.
- #routing_path ⇒ Object
-
#routing_path_and_extension ⇒ Object
splits the raw_path_info into a routing path, and an optional file extension for use with special media-type-specific file extension handling (where :media_type_extensions => true configured on the app).
-
#session ⇒ Object
For now, to do authentication you need some (rack) middleware that sets one of these env’s.
- #session_authenticated? ⇒ Boolean
Constructor Details
#initialize(app, env) ⇒ Request
Returns a new instance of Request.
6 7 8 9 |
# File 'lib/doze/request.rb', line 6 def initialize(app, env) @app = app super(env) end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
11 12 13 |
# File 'lib/doze/request.rb', line 11 def app @app end |
Instance Method Details
#entity ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/doze/request.rb', line 38 def entity return @entity if defined?(@entity) @entity = if media_type media_type.new_entity( :binary_data_stream => env['rack.input'], :binary_data_length => content_length && content_length.to_i, :encoding => content_charset, :media_type_params => media_type_params ) end end |
#extension ⇒ Object
87 88 89 |
# File 'lib/doze/request.rb', line 87 def extension routing_path_and_extension[1] end |
#get_or_head? ⇒ Boolean
29 30 31 32 |
# File 'lib/doze/request.rb', line 29 def get_or_head? method = @env["REQUEST_METHOD"] method == "GET" || method == "HEAD" end |
#media_type ⇒ Object
50 51 52 |
# File 'lib/doze/request.rb', line 50 def media_type @mt ||= (mt = super and Doze::MediaType[mt]) end |
#negotiator(ignore_unacceptable_accepts = false) ⇒ Object
Makes a Doze::Negotiator to do content negotiation on behalf of this request
92 93 94 |
# File 'lib/doze/request.rb', line 92 def negotiator(ignore_unacceptable_accepts=false) Doze::Negotiator.new(self, ignore_unacceptable_accepts) end |
#normalized_request_method ⇒ Object
this delibarately ignores the HEAD vs GET distinction; use head? to check
14 15 16 17 |
# File 'lib/doze/request.rb', line 14 def normalized_request_method method = @env["REQUEST_METHOD"] method == 'HEAD' ? 'get' : method.downcase end |
#options? ⇒ Boolean
34 35 36 |
# File 'lib/doze/request.rb', line 34 def @env["REQUEST_METHOD"] == 'OPTIONS' end |
#raw_path_info ⇒ Object
At this stage, we only care that the servlet spec says PATH_INFO is decoded so special case it. There might be others needed, but webrick and thin return an encoded PATH_INFO so this’ll do for now. bulknews.typepad.com/blog/2009/09/path_info-decoding-horrors.html java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/http/HttpServletRequest.html#getPathInfo%28%29
24 25 26 27 |
# File 'lib/doze/request.rb', line 24 def raw_path_info ((servlet_request = @env['java.servlet_request']) && raw_path_info_from_servlet_request(servlet_request)) || path_info end |
#routing_path ⇒ Object
83 84 85 |
# File 'lib/doze/request.rb', line 83 def routing_path routing_path_and_extension[0] end |
#routing_path_and_extension ⇒ Object
splits the raw_path_info into a routing path, and an optional file extension for use with special media-type-specific file extension handling (where :media_type_extensions => true configured on the app)
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/doze/request.rb', line 69 def routing_path_and_extension @routing_path_and_extension ||= begin path = raw_path_info extension = nil if @app.config[:media_type_extensions] && (match = EXTENSION_REGEXP.match(path)) path = match.pre_match extension = match[1] end [path, extension] end end |
#session ⇒ Object
For now, to do authentication you need some (rack) middleware that sets one of these env’s. See :session_from_rack_env under Doze::Application config
56 57 58 |
# File 'lib/doze/request.rb', line 56 def session @session ||= @app.config[:session_from_rack_env].call(@env) end |
#session_authenticated? ⇒ Boolean
60 61 62 |
# File 'lib/doze/request.rb', line 60 def session_authenticated? @session_authenticated ||= (session && @app.config[:session_authenticated].call(session)) end |