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

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

Methods included from Helpers::RequestHeadersHelper

#accepted_charsets, #accepted_charsets=, #accepted_language_ranges, #accepted_language_ranges=, #accepted_media_ranges, #accepted_media_ranges=, #from, #from=, #host, #host=, #max_forwards, #max_forwards=, #negotiate_charset, #negotiate_language_tag, #negotiate_media_type, #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(method, request_uri, headers, entity_body, options = {})

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 (Webbed::Method, String)
  • request_uri (Addressable::URI, String)
  • headers (Webbed::Headers, Hash)
  • entity_body (#to_s)
  • options (Hash) (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



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

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.fetch(:http_version, 1.1)
  self.scheme       = options.fetch(: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

- (Webbed::Method) method(*args)

The Method of the Request.

Returns:



55
56
57
58
# File 'lib/webbed/request.rb', line 55

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

- method=(method)

Sets the Method of the Request.

Parameters:



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

def method=(method)
  @method = Webbed::Method.lookup(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)


74
75
76
# File 'lib/webbed/request.rb', line 74

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