Class: Whoosh::Request
- Inherits:
-
Object
- Object
- Whoosh::Request
- Defined in:
- lib/whoosh/request.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#path_params ⇒ Object
Returns the value of attribute path_params.
Instance Method Summary collapse
- #body ⇒ Object
- #content_type ⇒ Object
- #cookies ⇒ Object
- #files ⇒ Object
- #headers ⇒ Object
- #id ⇒ Object
-
#initialize(env) ⇒ Request
constructor
A new instance of Request.
- #logger ⇒ Object
- #method ⇒ Object
- #params ⇒ Object
- #path ⇒ Object
- #query_params ⇒ Object
Constructor Details
#initialize(env) ⇒ Request
Returns a new instance of Request.
12 13 14 15 16 |
# File 'lib/whoosh/request.rb', line 12 def initialize(env) @env = env @rack_request = Rack::Request.new(env) @path_params = {} end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
10 11 12 |
# File 'lib/whoosh/request.rb', line 10 def env @env end |
#path_params ⇒ Object
Returns the value of attribute path_params.
9 10 11 |
# File 'lib/whoosh/request.rb', line 9 def path_params @path_params end |
Instance Method Details
#body ⇒ Object
34 35 36 |
# File 'lib/whoosh/request.rb', line 34 def body @body ||= parse_body end |
#content_type ⇒ Object
46 47 48 |
# File 'lib/whoosh/request.rb', line 46 def content_type @rack_request.content_type end |
#cookies ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/whoosh/request.rb', line 57 def @cookies ||= begin raw = @env["HTTP_COOKIE"] || "" raw.split(";").each_with_object({}) do |pair, h| k, v = pair.strip.split("=", 2) h[k] = v if k end end end |
#files ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/whoosh/request.rb', line 67 def files @files ||= begin storage = @env["whoosh.storage"] form_data = @rack_request.params form_data.each_with_object({}) do |(key, value), hash| next unless value.is_a?(Hash) && value[:tempfile] hash[key] = UploadedFile.new(value, storage: storage) end end end |
#headers ⇒ Object
38 39 40 |
# File 'lib/whoosh/request.rb', line 38 def headers @headers ||= extract_headers end |
#id ⇒ Object
42 43 44 |
# File 'lib/whoosh/request.rb', line 42 def id @id ||= @env["whoosh.request_id"] || headers["X-Request-Id"] || SecureRandom.uuid end |
#logger ⇒ Object
50 51 52 53 54 55 |
# File 'lib/whoosh/request.rb', line 50 def logger @logger ||= begin base_logger = @env["whoosh.logger"] base_logger&.with_context(request_id: id) end end |
#method ⇒ Object
18 19 20 |
# File 'lib/whoosh/request.rb', line 18 def method @rack_request.request_method end |
#params ⇒ Object
26 27 28 |
# File 'lib/whoosh/request.rb', line 26 def params @params ||= query_params.merge(@path_params) end |
#path ⇒ Object
22 23 24 |
# File 'lib/whoosh/request.rb', line 22 def path @rack_request.path_info end |
#query_params ⇒ Object
30 31 32 |
# File 'lib/whoosh/request.rb', line 30 def query_params @query_params ||= Rack::Utils.parse_query(@rack_request.query_string) end |