module Qeweney::RequestInfoMethods
def accept_encoding
TODO: should return encodings in client's order of preference (and take
def accept_encoding encoding = @headers['accept-encoding'] return [] unless encoding encoding.split(',').map { |i| i.strip } end
def connection
def connection @headers['connection'] end
def cookies
def cookies @cookies ||= parse_cookies(headers['cookie']) end
def forwarded_for
def forwarded_for @headers['x-forwarded-for'] end
def full_uri
def full_uri @full_uri = "#{scheme}://#{host}#{uri}" end
def host
def host @headers['host'] || @headers[':authority'] end
def method
def method @method ||= @headers[':method'].downcase end
def parse_cookies(cookies)
def parse_cookies(cookies) return {} unless cookies cookies.split(SEMICOLON).each_with_object({}) do |c, h| raise BadRequestError, 'Invalid cookie format' unless c.strip =~ COOKIE_RE key, value = Regexp.last_match[1..2] h[key] = EscapeUtils.unescape_uri(value) end end
def parse_query(query)
def parse_query(query) query.split('&').each_with_object({}) do |kv, h| k, v = kv.match(QUERY_KV_REGEXP)[1..2] h[k.to_sym] = v ? URI.decode_www_form_component(v) : true end end
def path
def path @path ||= uri.path end
def protocol
def protocol @protocol ||= @adapter.protocol end
def query
def query return @query if @query @query = (q = uri.query) ? parse_query(q) : {} end
def query_string
def query_string @query_string ||= uri.query end
def request_id
def request_id @headers['x-request-id'] end
def rewrite!(src, replacement)
-
(Qeweney::Request)
- self
Parameters:
-
replacement
(String
) -- replacement -
src
(String, Regexp
) -- src pattern
def rewrite!(src, replacement) @headers[':path'] = @headers[':path'] .gsub(src, replacement) .gsub('//', '/') @path = nil @uri = nil @full_uri = nil self end
def scheme
def scheme @scheme ||= @headers[':scheme'] end
def upgrade_protocol
def upgrade_protocol connection == 'upgrade' && @headers['upgrade']&.downcase end
def uri
def uri @uri ||= URI.parse(@headers[':path'] || '') end
def websocket_version
def websocket_version headers['sec-websocket-version'].to_i end