Class: Syntropy::Request
- Inherits:
-
Object
- Object
- Syntropy::Request
- Extended by:
- RequestInfoClassMethods
- Defined in:
- lib/syntropy/request.rb
Overview
Syntropy::Request represents an HTTP request. By interacting with the request, the app can extract request information and respond to the request.
Constant Summary collapse
- EMPTY_HEADERS =
{}.freeze
Constants included from RequestInfoClassMethods
Syntropy::RequestInfoClassMethods::MAX_PARAMETER_NAME_SIZE, Syntropy::RequestInfoClassMethods::MAX_PARAMETER_VALUE_SIZE, Syntropy::RequestInfoClassMethods::PARAMETER_RE
Constants included from ResponseMethods
Syntropy::ResponseMethods::WEBSOCKET_GUID
Constants included from RequestInfoMethods
Syntropy::RequestInfoMethods::COOKIE_RE, Syntropy::RequestInfoMethods::QUERY_KV_REGEXP, Syntropy::RequestInfoMethods::SEMICOLON
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#route ⇒ Object
Returns the value of attribute route.
-
#route_params ⇒ Object
readonly
Returns the value of attribute route_params.
-
#start_stamp ⇒ Object
readonly
Returns the value of attribute start_stamp.
Instance Method Summary collapse
-
#complete? ⇒ bool
Returns true if the request body has been consumed.
-
#ctx ⇒ Hash
Returns the request context, used to store auxiliary information.
-
#each_chunk ⇒ void
Reads request body chunks until the entire body is consumed, yielding each chunk to the given block.
-
#finish ⇒ void
Finish response.
-
#flash ⇒ Syntropy::Session::Flash
Returns the request flash session storage.
-
#headers_sent? ⇒ bool
Returns true if response headers were sent.
-
#initialize(headers, adapter) ⇒ void
constructor
Initializes the request.
-
#next_chunk ⇒ String?
Returns the next request body chunk.
-
#read ⇒ String?
(also: #body)
Reads the request body.
-
#respond(body, headers = EMPTY_HEADERS) ⇒ void
Sends a response.
-
#send_chunk(body, done: false) ⇒ void
(also: #<<)
Sends a response body chunk.
-
#send_headers(headers = EMPTY_HEADERS, empty_response = false) ⇒ void
Sends response headers.
-
#session ⇒ Syntropy::Session
Returns the request session.
Methods included from RequestInfoClassMethods
parse_form_data, parse_multipart_form_data, parse_multipart_form_data_part, parse_multipart_form_data_part_headers, parse_urlencoded_form_data
Methods included from TestRequestExtensions
#response_body, #response_content_type, #response_cookie, #response_headers, #response_json, #response_status
Methods included from ResponseMethods
#file_full_path, #json_pretty_response, #redirect, #redirect_to_host, #redirect_to_https, #respond_by_http_method, #respond_html, #respond_json, #respond_on_get, #respond_on_post, #respond_with_static_file, #serve_file, #serve_io, #set_cookie, #set_response_headers, #upgrade, #upgrade_to_websocket, #validate_static_file_cache
Methods included from RequestValidationMethods
#validate, #validate_cache, #validate_content_type, #validate_http_method, #validate_param
Methods included from RequestInfoMethods
#accept?, #accept_encoding, #auth_bearer_token, #browser?, #connection, #content_type, #cookies, #forwarded_for, #full_uri, #get_form_data, #host, #method, #parse_cookies, #parse_query, #path, #protocol, #query, #query_string, #request_id, #rewrite!, #scheme, #upgrade_protocol, #uri, #websocket_version
Constructor Details
#initialize(headers, adapter) ⇒ void
Initializes the request.
26 27 28 29 30 31 32 33 |
# File 'lib/syntropy/request.rb', line 26 def initialize(headers, adapter) @headers = headers @adapter = adapter @start_stamp = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) @route = nil @route_params = {} @ctx = nil end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
18 19 20 |
# File 'lib/syntropy/request.rb', line 18 def adapter @adapter end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
18 19 20 |
# File 'lib/syntropy/request.rb', line 18 def headers @headers end |
#route ⇒ Object
Returns the value of attribute route.
19 20 21 |
# File 'lib/syntropy/request.rb', line 19 def route @route end |
#route_params ⇒ Object (readonly)
Returns the value of attribute route_params.
18 19 20 |
# File 'lib/syntropy/request.rb', line 18 def route_params @route_params end |
#start_stamp ⇒ Object (readonly)
Returns the value of attribute start_stamp.
18 19 20 |
# File 'lib/syntropy/request.rb', line 18 def start_stamp @start_stamp end |
Instance Method Details
#complete? ⇒ bool
Returns true if the request body has been consumed.
70 71 72 |
# File 'lib/syntropy/request.rb', line 70 def complete? @adapter.complete?(self) end |
#ctx ⇒ Hash
Returns the request context, used to store auxiliary information.
38 39 40 |
# File 'lib/syntropy/request.rb', line 38 def ctx @ctx ||= {} end |
#each_chunk ⇒ void
This method returns an undefined value.
Reads request body chunks until the entire body is consumed, yielding each chunk to the given block.
53 54 55 56 57 |
# File 'lib/syntropy/request.rb', line 53 def each_chunk while (chunk = @adapter.get_body_chunk(self)) yield chunk end end |
#finish ⇒ void
This method returns an undefined value.
Finish response.
113 114 115 116 117 |
# File 'lib/syntropy/request.rb', line 113 def finish send_headers({}) unless @headers_sent @adapter.finish(self) end |
#flash ⇒ Syntropy::Session::Flash
Returns the request flash session storage.
136 137 138 |
# File 'lib/syntropy/request.rb', line 136 def flash session.flash end |
#headers_sent? ⇒ bool
Returns true if response headers were sent.
122 123 124 |
# File 'lib/syntropy/request.rb', line 122 def headers_sent? @headers_sent end |
#next_chunk ⇒ String?
Returns the next request body chunk.
45 46 47 |
# File 'lib/syntropy/request.rb', line 45 def next_chunk @adapter.get_body_chunk(self) end |
#read ⇒ String? Also known as: body
Reads the request body.
62 63 64 |
# File 'lib/syntropy/request.rb', line 62 def read @adapter.get_body(self) end |
#respond(body, headers = EMPTY_HEADERS) ⇒ void
This method returns an undefined value.
Sends a response.
81 82 83 84 |
# File 'lib/syntropy/request.rb', line 81 def respond(body, headers = EMPTY_HEADERS) @adapter.respond(self, body, headers) @headers_sent = true end |
#send_chunk(body, done: false) ⇒ void Also known as: <<
This method returns an undefined value.
Sends a response body chunk.
103 104 105 106 107 |
# File 'lib/syntropy/request.rb', line 103 def send_chunk(body, done: false) send_headers({}) unless @headers_sent @adapter.send_chunk(self, body, done: done) end |
#send_headers(headers = EMPTY_HEADERS, empty_response = false) ⇒ void
This method returns an undefined value.
Sends response headers.
91 92 93 94 95 96 |
# File 'lib/syntropy/request.rb', line 91 def send_headers(headers = EMPTY_HEADERS, empty_response = false) return if @headers_sent @headers_sent = true @adapter.send_headers(self, headers, empty_response: empty_response) end |
#session ⇒ Syntropy::Session
Returns the request session.
129 130 131 |
# File 'lib/syntropy/request.rb', line 129 def session @session ||= Session.new(self) end |