Module: Hanami::Action::Rack
- Defined in:
- gems/gems/hanami-controller-1.3.2/lib/hanami/action/rack.rb,
gems/gems/hanami-controller-1.3.2/lib/hanami/action/rack/file.rb,
gems/gems/hanami-controller-1.3.2/lib/hanami/action/rack/callable.rb,
gems/gems/hanami-controller-1.3.3/lib/hanami/action/rack.rb,
gems/gems/hanami-controller-1.3.3/lib/hanami/action/rack/file.rb,
gems/gems/hanami-controller-1.3.3/lib/hanami/action/rack/errors.rb,
gems/gems/hanami-controller-1.3.3/lib/hanami/action/rack/callable.rb
Overview
Rack integration API
Constant Summary
- ROUTER_PARSED_BODY =
The key that returns router parsed body from the Rack env
'router.parsed_body'.freeze
Instance Method Summary collapse
-
#body=(body) ⇒ void
private
Sets the body of the response.
-
#head? ⇒ TrueClass, FalseClass
private
Check if the current request is a HEAD.
-
#headers ⇒ Hash
protected
Gets the headers from the response.
- #parsed_request_body ⇒ Object protected deprecated Deprecated.
-
#request ⇒ Hanami::Action::Request
protected
Returns a Hanami specialized rack request.
-
#request_id ⇒ String
protected
Calculates an unique ID for the current request.
-
#send_file(path) ⇒ void
private
Send a file as response.
-
#status=(status) ⇒ void
private
Sets the HTTP status code for the response.
-
#unsafe_send_file(path) ⇒ void
private
Send a file as response from anywhere in the file system.
Instance Method Details
#body=(body) ⇒ void (private)
This method returns an undefined value.
Sets the body of the response
Source: | on GitHub
def body=(body) body = Array(body) unless body.respond_to?(:each) @_body = body end |
#head? ⇒ TrueClass, FalseClass (private)
Check if the current request is a HEAD
Source: | on GitHub
def head? request_method == HEAD end |
#headers ⇒ Hash (protected)
Gets the headers from the response
Source: | on GitHub
def headers @headers end |
#parsed_request_body ⇒ Object (protected)
Return parsed request body
Source: | on GitHub
def parsed_request_body Hanami::Utils::Deprecation.new('#parsed_request_body is deprecated and it will be removed in future versions') @_env.fetch(ROUTER_PARSED_BODY, nil) end |
#request ⇒ Hanami::Action::Request (protected)
Returns a Hanami specialized rack request
#request_id ⇒ String (protected)
Calculates an unique ID for the current request
Source: | on GitHub
def request_id # FIXME make this number configurable and document the probabilities of clashes @request_id ||= SecureRandom.hex(DEFAULT_REQUEST_ID_LENGTH) end |
#send_file(path) ⇒ void (private)
This method returns an undefined value.
Send a file as response. This method only sends files from the public directory
It automatically handle the following cases:
-
Content-Type
andContent-Length
-
File Not found (returns a 404)
-
Conditional GET (via
If-Modified-Since
header) -
Range requests (via
Range
header)
Source: | on GitHub
def send_file(path) _send_file( File.new(path, self.class.configuration.public_directory).call(@_env) ) end |
#status=(status) ⇒ void (private)
This method returns an undefined value.
Sets the HTTP status code for the response
Source: | on GitHub
def status=(status) @_status = status end |
#unsafe_send_file(path) ⇒ void (private)
This method returns an undefined value.
Send a file as response from anywhere in the file system.
Source: | on GitHub
def unsafe_send_file(path) directory = self.class.configuration.root_directory if Pathname.new(path).relative? _send_file( File.new(path, directory).call(@_env) ) end |