Class: Jimmu::Request
- Inherits:
-
Object
- Object
- Jimmu::Request
- Defined in:
- lib/jimmu.rb
Overview
A parsed HTTP request. Constructed once per connection by Application's connection-handling code; passed into Context.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#http_method ⇒ Object
readonly
Returns the value of attribute http_method.
-
#http_version ⇒ Object
readonly
Returns the value of attribute http_version.
-
#ip ⇒ Object
readonly
Returns the value of attribute ip.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#query_string ⇒ Object
readonly
Returns the value of attribute query_string.
-
#raw_headers ⇒ Object
readonly
Returns the value of attribute raw_headers.
-
#route_params ⇒ Object
Returns the value of attribute route_params.
Instance Method Summary collapse
- #body_params ⇒ Object
- #content_type ⇒ Object
- #header(name) ⇒ Object
-
#initialize(http_method:, path:, query_string:, headers:, body:, ip:) ⇒ Request
constructor
A new instance of Request.
-
#method ⇒ Object
Public DSL name (spec: request.method).
-
#params ⇒ Object
Query params, then body params, then route (file-based dynamic segment) params, then uploaded files -- later sources win on key collision, with route params taking precedence as the most specific/intentional source, and uploaded files layered on top since their field names are defined by the form itself.
- #query_params ⇒ Object
- #uploaded_files ⇒ Object
Constructor Details
#initialize(http_method:, path:, query_string:, headers:, body:, ip:) ⇒ Request
Returns a new instance of Request.
499 500 501 502 503 504 505 506 507 |
# File 'lib/jimmu.rb', line 499 def initialize(http_method:, path:, query_string:, headers:, body:, ip:) @http_method = http_method @path = path @query_string = query_string || '' @raw_headers = headers # Hash, lowercase String keys => String values @body = body || ''.b @ip = ip @route_params = {} end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
496 497 498 |
# File 'lib/jimmu.rb', line 496 def body @body end |
#http_method ⇒ Object (readonly)
Returns the value of attribute http_method.
496 497 498 |
# File 'lib/jimmu.rb', line 496 def http_method @http_method end |
#http_version ⇒ Object (readonly)
Returns the value of attribute http_version.
496 497 498 |
# File 'lib/jimmu.rb', line 496 def http_version @http_version end |
#ip ⇒ Object (readonly)
Returns the value of attribute ip.
496 497 498 |
# File 'lib/jimmu.rb', line 496 def ip @ip end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
496 497 498 |
# File 'lib/jimmu.rb', line 496 def path @path end |
#query_string ⇒ Object (readonly)
Returns the value of attribute query_string.
496 497 498 |
# File 'lib/jimmu.rb', line 496 def query_string @query_string end |
#raw_headers ⇒ Object (readonly)
Returns the value of attribute raw_headers.
496 497 498 |
# File 'lib/jimmu.rb', line 496 def raw_headers @raw_headers end |
#route_params ⇒ Object
Returns the value of attribute route_params.
497 498 499 |
# File 'lib/jimmu.rb', line 497 def route_params @route_params end |
Instance Method Details
#body_params ⇒ Object
532 533 534 |
# File 'lib/jimmu.rb', line 532 def body_params @body_params ||= compute_body_params end |
#content_type ⇒ Object
518 519 520 |
# File 'lib/jimmu.rb', line 518 def content_type header('content-type') end |
#header(name) ⇒ Object
514 515 516 |
# File 'lib/jimmu.rb', line 514 def header(name) @raw_headers[name.to_s.downcase] end |
#method ⇒ Object
Public DSL name (spec: request.method)
510 511 512 |
# File 'lib/jimmu.rb', line 510 def method @http_method end |
#params ⇒ Object
Query params, then body params, then route (file-based dynamic segment) params, then uploaded files -- later sources win on key collision, with route params taking precedence as the most specific/intentional source, and uploaded files layered on top since their field names are defined by the form itself.
548 549 550 |
# File 'lib/jimmu.rb', line 548 def params @params ||= query_params.merge(body_params).merge(route_params).merge(uploaded_files) end |
#query_params ⇒ Object
522 523 524 525 526 527 528 529 530 |
# File 'lib/jimmu.rb', line 522 def query_params @query_params ||= begin h = {} URI.decode_www_form(@query_string, Encoding::UTF_8).each { |k, v| h[k.to_sym] = v } unless @query_string.empty? h rescue ArgumentError {} end end |
#uploaded_files ⇒ Object
536 537 538 539 540 541 |
# File 'lib/jimmu.rb', line 536 def uploaded_files @uploaded_files ||= begin compute_body_params @uploaded_files_cache || {} end end |