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.
19
20
21
22
23
24
25
26
|
# File 'lib/syntropy/request.rb', line 19
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.
16
17
18
|
# File 'lib/syntropy/request.rb', line 16
def adapter
@adapter
end
|
Returns the value of attribute headers.
16
17
18
|
# File 'lib/syntropy/request.rb', line 16
def
@headers
end
|
#route ⇒ Object
Returns the value of attribute route.
17
18
19
|
# File 'lib/syntropy/request.rb', line 17
def route
@route
end
|
#route_params ⇒ Object
Returns the value of attribute route_params.
16
17
18
|
# File 'lib/syntropy/request.rb', line 16
def route_params
@route_params
end
|
#start_stamp ⇒ Object
Returns the value of attribute start_stamp.
16
17
18
|
# File 'lib/syntropy/request.rb', line 16
def start_stamp
@start_stamp
end
|
Instance Method Details
#complete? ⇒ Boolean
48
49
50
|
# File 'lib/syntropy/request.rb', line 48
def complete?
@adapter.complete?(self)
end
|
#ctx ⇒ Object
Returns the request context
29
30
31
|
# File 'lib/syntropy/request.rb', line 29
def ctx
@ctx ||= {}
end
|
#each_chunk ⇒ Object
37
38
39
40
41
|
# File 'lib/syntropy/request.rb', line 37
def each_chunk
while (chunk = @adapter.get_body_chunk(self))
yield chunk
end
end
|
#finish ⇒ Object
73
74
75
76
77
|
# File 'lib/syntropy/request.rb', line 73
def finish
({}) unless @headers_sent
@adapter.finish(self)
end
|
79
80
81
|
# File 'lib/syntropy/request.rb', line 79
def
@headers_sent
end
|
#next_chunk ⇒ Object
33
34
35
|
# File 'lib/syntropy/request.rb', line 33
def next_chunk
@adapter.get_body_chunk(self)
end
|
#read ⇒ Object
Also known as:
body
43
44
45
|
# File 'lib/syntropy/request.rb', line 43
def read
@adapter.get_body(self)
end
|
#respond(body, headers = EMPTY_HEADERS) ⇒ Object
54
55
56
57
|
# File 'lib/syntropy/request.rb', line 54
def respond(body, = EMPTY_HEADERS)
@adapter.respond(self, body, )
@headers_sent = true
end
|
#response_body ⇒ Object
36
37
38
|
# File 'lib/syntropy/test.rb', line 36
def response_body
adapter.response_body
end
|
#response_content_type ⇒ Object
45
46
47
48
49
50
51
52
53
|
# File 'lib/syntropy/test.rb', line 45
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
55
56
57
58
59
60
61
62
63
|
# File 'lib/syntropy/test.rb', line 55
def response_cookie(name)
sc = ['Set-Cookie']
return nil if !sc
m = sc.match(/#{name}=([^\s]+)$/)
return nil if !m
m[1]
end
|
28
29
30
|
# File 'lib/syntropy/test.rb', line 28
def
adapter.
end
|
#response_json ⇒ Object
40
41
42
43
|
# File 'lib/syntropy/test.rb', line 40
def response_json
raise if response_content_type != 'application/json'
JSON.parse(response_body)
end
|
#response_status ⇒ Object
32
33
34
|
# File 'lib/syntropy/test.rb', line 32
def response_status
adapter.status
end
|
#rx_incr(count) ⇒ Object
83
84
85
|
# File 'lib/syntropy/request.rb', line 83
def rx_incr(count)
[':rx'] ? [':rx'] += count : [':rx'] = count
end
|
#send_chunk(body, done: false) ⇒ Object
Also known as:
<<
66
67
68
69
70
|
# File 'lib/syntropy/request.rb', line 66
def send_chunk(body, done: false)
({}) unless @headers_sent
@adapter.send_chunk(self, body, done: done)
end
|
59
60
61
62
63
64
|
# File 'lib/syntropy/request.rb', line 59
def ( = EMPTY_HEADERS, empty_response = false)
return if @headers_sent
@headers_sent = true
@adapter.(self, , empty_response: empty_response)
end
|
#total_transfer ⇒ Object
95
96
97
|
# File 'lib/syntropy/request.rb', line 95
def total_transfer
([':rx'] || 0) + ([':tx'] || 0)
end
|
#transfer_counts ⇒ Object
91
92
93
|
# File 'lib/syntropy/request.rb', line 91
def transfer_counts
[[':rx'], [':tx']]
end
|
#tx_incr(count) ⇒ Object
87
88
89
|
# File 'lib/syntropy/request.rb', line 87
def tx_incr(count)
[':tx'] ? [':tx'] += count : [':tx'] = count
end
|