Class: Syntropy::Request
Constant Summary
collapse
{}.freeze
Syntropy::RequestInfoClassMethods::MAX_PARAMETER_NAME_SIZE, Syntropy::RequestInfoClassMethods::MAX_PARAMETER_VALUE_SIZE, Syntropy::RequestInfoClassMethods::PARAMETER_RE
Syntropy::ResponseMethods::WEBSOCKET_GUID
Syntropy::RequestInfoMethods::COOKIE_RE, Syntropy::RequestInfoMethods::QUERY_KV_REGEXP, Syntropy::RequestInfoMethods::SEMICOLON
Instance Attribute Summary collapse
Instance Method Summary
collapse
parse_form_data, parse_multipart_form_data, parse_multipart_form_data_part, parse_multipart_form_data_part_headers, parse_urlencoded_form_data
#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
#validate, #validate_cache, #validate_content_type, #validate_http_method, #validate_param
#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) ⇒ Request
Returns a new instance of Request.
20
21
22
23
24
25
26
27
|
# File 'lib/syntropy/request.rb', line 20
def initialize(, adapter)
@headers =
@adapter = adapter
@start_stamp = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
@route = nil
@route_params = {}
@ctx = nil
end
|
Instance Attribute Details
#adapter ⇒ Object
Returns the value of attribute adapter.
17
18
19
|
# File 'lib/syntropy/request.rb', line 17
def adapter
@adapter
end
|
Returns the value of attribute headers.
17
18
19
|
# File 'lib/syntropy/request.rb', line 17
def
@headers
end
|
#route ⇒ Object
Returns the value of attribute route.
18
19
20
|
# File 'lib/syntropy/request.rb', line 18
def route
@route
end
|
#route_params ⇒ Object
Returns the value of attribute route_params.
17
18
19
|
# File 'lib/syntropy/request.rb', line 17
def route_params
@route_params
end
|
#start_stamp ⇒ Object
Returns the value of attribute start_stamp.
17
18
19
|
# File 'lib/syntropy/request.rb', line 17
def start_stamp
@start_stamp
end
|
Instance Method Details
#complete? ⇒ Boolean
49
50
51
|
# File 'lib/syntropy/request.rb', line 49
def complete?
@adapter.complete?(self)
end
|
#ctx ⇒ Object
Returns the request context
30
31
32
|
# File 'lib/syntropy/request.rb', line 30
def ctx
@ctx ||= {}
end
|
#each_chunk ⇒ Object
38
39
40
41
42
|
# File 'lib/syntropy/request.rb', line 38
def each_chunk
while (chunk = @adapter.get_body_chunk(self))
yield chunk
end
end
|
#finish ⇒ Object
74
75
76
77
78
|
# File 'lib/syntropy/request.rb', line 74
def finish
({}) unless @headers_sent
@adapter.finish(self)
end
|
#flash ⇒ Object
104
105
106
|
# File 'lib/syntropy/request.rb', line 104
def flash
session.flash
end
|
80
81
82
|
# File 'lib/syntropy/request.rb', line 80
def
@headers_sent
end
|
#next_chunk ⇒ Object
34
35
36
|
# File 'lib/syntropy/request.rb', line 34
def next_chunk
@adapter.get_body_chunk(self)
end
|
#read ⇒ Object
Also known as:
body
44
45
46
|
# File 'lib/syntropy/request.rb', line 44
def read
@adapter.get_body(self)
end
|
#respond(body, headers = EMPTY_HEADERS) ⇒ Object
55
56
57
58
|
# File 'lib/syntropy/request.rb', line 55
def respond(body, = EMPTY_HEADERS)
@adapter.respond(self, body, )
@headers_sent = true
end
|
#response_body ⇒ Object
119
120
121
|
# File 'lib/syntropy/test.rb', line 119
def response_body
adapter.response_body
end
|
#response_content_type ⇒ Object
128
129
130
131
132
133
134
135
136
|
# File 'lib/syntropy/test.rb', line 128
def response_content_type
ct = ['Content-Type']
return nil if !ct
m = ct.match(/^([^;]+)/)
return nil if !m
m[1]
end
|
#response_cookie(name) ⇒ Object
138
139
140
141
142
143
144
145
146
|
# File 'lib/syntropy/test.rb', line 138
def response_cookie(name)
sc = ['Set-Cookie']
return nil if !sc
m = sc.match(/#{name}=([^\s]+)$/)
return nil if !m
m[1]
end
|
111
112
113
|
# File 'lib/syntropy/test.rb', line 111
def
adapter.
end
|
#response_json ⇒ Object
123
124
125
126
|
# File 'lib/syntropy/test.rb', line 123
def response_json
raise if response_content_type != 'application/json'
JSON.parse(response_body)
end
|
#response_status ⇒ Object
115
116
117
|
# File 'lib/syntropy/test.rb', line 115
def response_status
adapter.status
end
|
#rx_incr(count) ⇒ Object
84
85
86
|
# File 'lib/syntropy/request.rb', line 84
def rx_incr(count)
[':rx'] ? [':rx'] += count : [':rx'] = count
end
|
#send_chunk(body, done: false) ⇒ Object
Also known as:
<<
67
68
69
70
71
|
# File 'lib/syntropy/request.rb', line 67
def send_chunk(body, done: false)
({}) unless @headers_sent
@adapter.send_chunk(self, body, done: done)
end
|
60
61
62
63
64
65
|
# File 'lib/syntropy/request.rb', line 60
def ( = EMPTY_HEADERS, empty_response = false)
return if @headers_sent
@headers_sent = true
@adapter.(self, , empty_response: empty_response)
end
|
#session ⇒ Object
100
101
102
|
# File 'lib/syntropy/request.rb', line 100
def session
@session ||= Session.new(self)
end
|
#total_transfer ⇒ Object
96
97
98
|
# File 'lib/syntropy/request.rb', line 96
def total_transfer
([':rx'] || 0) + ([':tx'] || 0)
end
|
#transfer_counts ⇒ Object
92
93
94
|
# File 'lib/syntropy/request.rb', line 92
def transfer_counts
[[':rx'], [':tx']]
end
|
#tx_incr(count) ⇒ Object
88
89
90
|
# File 'lib/syntropy/request.rb', line 88
def tx_incr(count)
[':tx'] ? [':tx'] += count : [':tx'] = count
end
|