Class: Bijou::HttpRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/bijou/httprequest.rb

Overview

This class represents an incoming HTTP request, presenting a common interface to the Bijou component regardless of the server environment.

Direct Known Subclasses

CGI::Request, Console::Request, WEBrick::Request

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHttpRequest

Returns a new instance of HttpRequest.



14
15
16
17
18
19
20
21
# File 'lib/bijou/httprequest.rb', line 14

def initialize
  @params = {}
  @query_string = {}
  @form = {}
  @server_variables = {}
  @cookies = {}
  @http_method = ''
end

Instance Attribute Details

#cookiesObject (readonly)

A hash containing cookies sent by the client.



56
57
58
# File 'lib/bijou/httprequest.rb', line 56

def cookies
  @cookies
end

#formObject (readonly)

Returns a hash containing form data passed via the HTTP POST action. Synonym for #post.



29
30
31
# File 'lib/bijou/httprequest.rb', line 29

def form
  @form
end

#http_methodObject (readonly)

A string representing the HTTP request method (e.g., GET, POST, or HEAD).



59
60
61
# File 'lib/bijou/httprequest.rb', line 59

def http_method
  @http_method
end

#paramsObject (readonly)

Returns a hash containing the combined values of the query string, post data, and cookies.



33
34
35
# File 'lib/bijou/httprequest.rb', line 33

def params
  @params
end

#query_stringObject (readonly)

Returns a hash containing items passed via the HTTP query string. Synonym for #get.



25
26
27
# File 'lib/bijou/httprequest.rb', line 25

def query_string
  @query_string
end

#server_variablesObject (readonly)

A hash containing standard CGI environment variables.

AUTH_TYPE               HTTP_HOST          REMOTE_IDENT
CONTENT_LENGTH          HTTP_NEGOTIATE     REMOTE_USER
CONTENT_TYPE            HTTP_PRAGMA        REQUEST_METHOD
GATEWAY_INTERFACE       HTTP_REFERER       SCRIPT_NAME
HTTP_ACCEPT             HTTP_USER_AGENT    SERVER_NAME
HTTP_ACCEPT_CHARSET     PATH_INFO          SERVER_PORT
HTTP_ACCEPT_ENCODING    PATH_TRANSLATED    SERVER_PROTOCOL
HTTP_ACCEPT_LANGUAGE    QUERY_STRING       SERVER_SOFTWARE
HTTP_CACHE_CONTROL      REMOTE_ADDR
HTTP_FROM               REMOTE_HOST

As well as additions that aren’t present in cgi.rb.

REQUEST_URI


53
54
55
# File 'lib/bijou/httprequest.rb', line 53

def server_variables
  @server_variables
end

Instance Method Details

#getObject

Returns a hash containing items passed via the HTTP query string. Synonym for #query_string.



63
64
65
# File 'lib/bijou/httprequest.rb', line 63

def get
  @query_string
end

#physical_pathObject



96
97
98
# File 'lib/bijou/httprequest.rb', line 96

def physical_path
  @server_variables['PATH_TRANSLATED']
end

#postObject

Returns a hash containing form data passed via the HTTP POST action. Synonym for #form.



69
70
71
# File 'lib/bijou/httprequest.rb', line 69

def post
  @form
end

#refererObject



78
79
80
# File 'lib/bijou/httprequest.rb', line 78

def referer
  @server_variables['HTTP_REFERER']
end

#referrerObject

TODO: These should be moved to CGI::Request



74
75
76
# File 'lib/bijou/httprequest.rb', line 74

def referrer
  @server_variables['HTTP_REFERER']
end

#request_methodObject



100
101
102
# File 'lib/bijou/httprequest.rb', line 100

def request_method
  @server_variables['REQUEST_METHOD']
end

#user_agentObject



104
105
106
# File 'lib/bijou/httprequest.rb', line 104

def user_agent
  @server_variables['HTTP_USER_AGENT']
end

#virtual_pathObject

++



91
92
93
94
# File 'lib/bijou/httprequest.rb', line 91

def virtual_path
#      @server_variables['REQUEST_URI']
  @server_variables['PATH_INFO']
end