Class: Webbed::Request

Overview

Representation of an HTTP Request.

This class contains the absolute minimum for accessing the different parts of an HTTP Request. Helper modules provide far more functionality.

Instance Attribute Summary collapse

Attributes included from GenericMessage

#entity_body, #headers, #http_version

Instance Method Summary collapse

Methods included from Helpers::EntityHeadersHelper

#content_length, #content_length=, #content_location, #content_location=, #content_md5, #content_md5=, #content_type, #content_type=

Methods included from Helpers::RequestHeadersHelper

#from, #from=, #host, #host=, #max_forwards, #max_forwards=, #referer, #referer=

Methods included from Helpers::SchemeHelper

#default_port, #secure?

Methods included from Helpers::RackRequestHelper

included

Methods included from Helpers::RequestURIHelper

included, #uri

Methods included from Helpers::MethodHelper

#connect?, #delete?, #get?, #head?, #idempotent?, #options?, #patch?, #post?, #put?, #safe?, #trace?

Methods included from GenericMessage

#to_s

Constructor Details

#initialize(method, request_uri, headers, entity_body, options = {}) ⇒ Request

Creates a new Request.

The method converts the values passed in to their proper types.

Examples:

Webbed::Request.new('GET', 'http://example.com', {}, '')

Parameters:

  • method (Method, String)
  • request_uri (Addressable::URI, String)
  • headers (Headers, Hash)
  • entity_body (#to_s)
  • options (Array) (defaults to: {})

    the options to create the Request with

Options Hash (options):

  • :http_version (#to_s) — default: 1.1

    the HTTP-Version of the Request

  • :scheme ('http', 'https') — default: 'http'

    the scheme of the Request



45
46
47
48
49
50
51
52
# File 'lib/webbed/request.rb', line 45

def initialize(method, request_uri, headers, entity_body, options = {})
  self.method       = method
  self.request_uri  = request_uri
  self.headers      = headers
  self.entity_body  = entity_body
  self.http_version = options[:http_version] || 1.1
  self.scheme       = options[:scheme] || 'http'
end

Instance Attribute Details

#request_uriAddressable::URI

Note:

Helpers::RequestURIHelper aliases this method to #request_url.

The Request-URI of the Request.

The method automatically converts the new value to an instance of Addressable::URI if it is not already one.

Returns:

  • (Addressable::URI)


18
19
20
# File 'lib/webbed/request.rb', line 18

def request_uri
  @request_uri
end

#scheme'http', 'https'

The scheme of the Request.

Returns:

  • ('http', 'https')


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

def scheme
  @scheme
end

Instance Method Details

#method(*args) ⇒ Method

The Method of the Request.

Returns:



57
58
59
60
# File 'lib/webbed/request.rb', line 57

def method(*args)
  return super(*args) unless args.empty?
  @method
end

#method=(method)

Sets the Method of the Request.

Parameters:



65
66
67
# File 'lib/webbed/request.rb', line 65

def method=(method)
  @method = Webbed::Method.new(method)
end

#request_lineString Also known as: start_line

The Request-Line of the Request as defined in RFC 2616.

Examples:

request = Webbed::Request.new(['GET', 'http://example.com', {}, ''])
request.request_line # => "GET * HTTP/1.1\r\n"

Returns:

  • (String)


76
77
78
# File 'lib/webbed/request.rb', line 76

def request_line
  "#{method} #{request_uri} #{http_version}\r\n"
end