Class: Request

Inherits:
Object
  • Object
show all
Includes:
AbstractType, Adamantium::Flat
Defined in:
lib/request.rb,
lib/request/key.rb,
lib/request/rack.rb,
lib/request/method.rb,
lib/request/protocol.rb

Overview

Library namespace and abstract base class

Direct Known Subclasses

Rack

Defined Under Namespace

Classes: Key, Method, Protocol, Rack

Constant Summary collapse

KEYS =
%W(
  path_info protocol port request_method
  host if_modified_since query_params query_params_hash
  query_string content_length content_type body
).map(&:to_sym).freeze
METHODS =
(KEYS + %W(rack_env get? post?)).map(&:to_sym).freeze

Instance Method Summary collapse

Instance Method Details

#absolute_uriString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return absolute uri

Returns:

  • (String)


120
121
122
# File 'lib/request.rb', line 120

def absolute_uri
  "#{root_uri}#{path_info}"
end

#absolute_uri_path(path) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return absolute uri for path

Parameters:

  • (Path)

Returns:

  • (String)


132
133
134
# File 'lib/request.rb', line 132

def absolute_uri_path(path)
  "#{root_uri}#{path}"
end

#hostString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return host

Returns:

  • (String)


67
# File 'lib/request.rb', line 67

abstract_method :host

#host_with_portString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return host with optional port

Only returns port if protocols default port diffes from actual port.

Returns:

  • (String)


155
156
157
158
159
160
161
162
# File 'lib/request.rb', line 155

def host_with_port
  uhost, uport = self.host, self.port
  if port != protocol.default_port
    "#{uhost}:#{uport}"
  else
    uhost
  end
end

#if_modified_sinceTime?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return if modified since header

Returns:

  • (Time)

    if present

  • (nil)

    otherwise



51
# File 'lib/request.rb', line 51

abstract_method :if_modified_since

#path_infoString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return path info

Returns:

  • (String)


59
# File 'lib/request.rb', line 59

abstract_method :path_info

#portInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return port

Returns:

  • (Integer)


75
# File 'lib/request.rb', line 75

abstract_method :port

#protocolProtocol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return protocol

Returns:



39
# File 'lib/request.rb', line 39

abstract_method :protocol

#query_paramsArray

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return query params

Returns:

  • (Array)


91
# File 'lib/request.rb', line 91

abstract_method :query_params

#query_params_hashHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return query params hash

Returns:

  • (Hash)


99
100
101
102
103
# File 'lib/request.rb', line 99

def query_params_hash
  query_params.each_with_object({}) do |(key, value), hash|
    hash[key]=value
  end
end

#query_stringString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return query string

Returns:

  • (String)


112
# File 'lib/request.rb', line 112

abstract_method :query_string

#request_methodMethod

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return request method

Returns:



83
# File 'lib/request.rb', line 83

abstract_method :request_method

#root_uriString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return root uri

Returns:

  • (String)


142
143
144
# File 'lib/request.rb', line 142

def root_uri
  "#{protocol.name}://#{host_with_port}"
end

#uidString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return unique id

Returns:

  • (String)


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

def uid
  SecureRandom.hex(6)
end