Class: Syntropy::Request

Inherits:
Object
  • Object
show all
Extended by:
RequestInfoClassMethods
Includes:
RequestInfoMethods, RequestValidationMethods, ResponseMethods
Defined in:
lib/syntropy/request.rb

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

Instance Method Summary collapse

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 ResponseMethods

#file_full_path, #html_response, #json_pretty_response, #json_response, #redirect, #redirect_to_host, #redirect_to_https, #respond_by_http_method, #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_http_method, #validate_param

Methods included from RequestInfoMethods

#accept?, #accept_encoding, #browser?, #connection, #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(headers, adapter)
  @headers  = headers
  @adapter  = adapter
  @start_stamp = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
  @route = nil
  @route_params = {}
  @ctx = nil
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



16
17
18
# File 'lib/syntropy/request.rb', line 16

def adapter
  @adapter
end

#headersObject (readonly)

Returns the value of attribute headers.



16
17
18
# File 'lib/syntropy/request.rb', line 16

def headers
  @headers
end

#routeObject

Returns the value of attribute route.



17
18
19
# File 'lib/syntropy/request.rb', line 17

def route
  @route
end

#route_paramsObject (readonly)

Returns the value of attribute route_params.



16
17
18
# File 'lib/syntropy/request.rb', line 16

def route_params
  @route_params
end

#start_stampObject (readonly)

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

Returns:

  • (Boolean)


48
49
50
# File 'lib/syntropy/request.rb', line 48

def complete?
  @adapter.complete?(self)
end

#ctxObject

Returns the request context



29
30
31
# File 'lib/syntropy/request.rb', line 29

def ctx
  @ctx ||= {}
end

#each_chunkObject



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

#finishObject



73
74
75
76
77
# File 'lib/syntropy/request.rb', line 73

def finish
  send_headers({}) unless @headers_sent

  @adapter.finish(self)
end

#headers_sent?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/syntropy/request.rb', line 79

def headers_sent?
  @headers_sent
end

#next_chunkObject



33
34
35
# File 'lib/syntropy/request.rb', line 33

def next_chunk
  @adapter.get_body_chunk(self)
end

#readObject 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, headers = EMPTY_HEADERS)
  @adapter.respond(self, body, headers)
  @headers_sent = true
end

#rx_incr(count) ⇒ Object



83
84
85
# File 'lib/syntropy/request.rb', line 83

def rx_incr(count)
  headers[':rx'] ? headers[':rx'] += count : headers[':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)
  send_headers({}) unless @headers_sent

  @adapter.send_chunk(self, body, done: done)
end

#send_headers(headers = EMPTY_HEADERS, empty_response = false) ⇒ Object



59
60
61
62
63
64
# File 'lib/syntropy/request.rb', line 59

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

#total_transferObject



95
96
97
# File 'lib/syntropy/request.rb', line 95

def total_transfer
  (headers[':rx'] || 0) + (headers[':tx'] || 0)
end

#transfer_countsObject



91
92
93
# File 'lib/syntropy/request.rb', line 91

def transfer_counts
  [headers[':rx'], headers[':tx']]
end

#tx_incr(count) ⇒ Object



87
88
89
# File 'lib/syntropy/request.rb', line 87

def tx_incr(count)
  headers[':tx'] ? headers[':tx'] += count : headers[':tx'] = count
end