Class: Webbed::Request

Inherits:
Object
  • Object
show all
Includes:
GenericMessage, Helpers::EntityHeadersHelper, Helpers::MethodHelper, Helpers::RackRequestHelper, Helpers::RequestHeadersHelper, Helpers::RequestURIHelper, Helpers::SchemeHelper
Defined in:
lib/webbed/request.rb

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

- (Request) initialize(request_array, options = {})

Creates a new Request

The attributes of the Request are passed in as an array. In order, they go:

  1. Method
  2. Request-URI
  3. Headers
  4. Entity Body

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

Examples:

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

Parameters:

  • request_array (Array)
  • 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



50
51
52
53
54
55
56
57
# File 'lib/webbed/request.rb', line 50

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

Instance Attribute Details

- (Addressable::URI) request_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

- ('http', 'https') scheme

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) method(*args)

The Method of the Request

Returns:



62
63
64
65
# File 'lib/webbed/request.rb', line 62

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

- method=(new_method)

Sets the Method of the Request

Parameters:



70
71
72
# File 'lib/webbed/request.rb', line 70

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

- (String) request_line 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)


81
82
83
# File 'lib/webbed/request.rb', line 81

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