Class: Anorexic::HTTPRequest

Inherits:
Hash
  • Object
show all
Defined in:
lib/anorexic/server/protocols/http_request.rb

Overview

class is the base for the HTTP server.

the class is initialized with a TCP/IP connection socket and starts an event driven cycle using the `EventStack.push` and `EventStack.reverse_async`.

to-do: fox logging.

Instance Method Summary collapse

Constructor Details

#initialize(service) ⇒ HTTPRequest

Returns a new instance of HTTPRequest.


11
12
13
14
# File 'lib/anorexic/server/protocols/http_request.rb', line 11

def initialize service
	super()
	self[:anorexic_service] = service
end

Instance Method Details

#base_url(switch_protocol = nil) ⇒ Object

the base url ([http/https]://host)


58
59
60
# File 'lib/anorexic/server/protocols/http_request.rb', line 58

def base_url switch_protocol = nil
	"#{switch_protocol || self[:requested_protocol]}://#{self[:host_name]}#{self[:port]? ":#{self[:port]}" : ''}"
end

#connect?Boolean

returns true of the method == CONNECT

Returns:

  • (Boolean)

106
107
108
# File 'lib/anorexic/server/protocols/http_request.rb', line 106

def connect?
	self[:method] == 'CONNECT'
end

#cookiesObject

the cookies sent by the client.


35
36
37
# File 'lib/anorexic/server/protocols/http_request.rb', line 35

def cookies
	self[:cookies]
end

#delete?Boolean

returns true of the method == DELETE

Returns:

  • (Boolean)

94
95
96
# File 'lib/anorexic/server/protocols/http_request.rb', line 94

def delete?
	self[:method] == 'DELETE'
end

#get?Boolean

returns true of the method == GET

Returns:

  • (Boolean)

78
79
80
# File 'lib/anorexic/server/protocols/http_request.rb', line 78

def get?
	self[:method] == 'GET'
end

#handlerObject

the handler dealing with this request


71
72
73
# File 'lib/anorexic/server/protocols/http_request.rb', line 71

def handler
	self[:anorexic_service].handler
end

#head?Boolean

returns true of the method == HEAD

Returns:

  • (Boolean)

82
83
84
# File 'lib/anorexic/server/protocols/http_request.rb', line 82

def head?
	self[:method] == 'HEAD'
end

#headersObject

the request's headers


19
20
21
# File 'lib/anorexic/server/protocols/http_request.rb', line 19

def headers
	self.select {|k,v| k.is_a? String }
end

#options?Boolean

returns true of the method == OPTIONS

Returns:

  • (Boolean)

102
103
104
# File 'lib/anorexic/server/protocols/http_request.rb', line 102

def options?
	self[:method] == 'OPTIONS'
end

#original_pathObject

the original (frozen) path (resource requested).


45
46
47
# File 'lib/anorexic/server/protocols/http_request.rb', line 45

def original_path
	self[:original_path]
end

#paramsObject

the parameters sent by the client.


31
32
33
# File 'lib/anorexic/server/protocols/http_request.rb', line 31

def params
	self[:params]
end

#patch?Boolean

returns true of the method == PATCH

Returns:

  • (Boolean)

110
111
112
# File 'lib/anorexic/server/protocols/http_request.rb', line 110

def patch?
	self[:method] == 'PATCH'
end

#pathObject

the requested path (rewritable).


50
51
52
# File 'lib/anorexic/server/protocols/http_request.rb', line 50

def path
	self[:path]
end

#path=(new_path) ⇒ Object


53
54
55
# File 'lib/anorexic/server/protocols/http_request.rb', line 53

def path=(new_path)
	self[:path] = new_path
end

#post?Boolean

returns true of the method == POST

Returns:

  • (Boolean)

86
87
88
# File 'lib/anorexic/server/protocols/http_request.rb', line 86

def post?
	self[:method] == 'POST'
end

#protocolObject

the protocol managing this request


67
68
69
# File 'lib/anorexic/server/protocols/http_request.rb', line 67

def protocol
	self[:requested_protocol]
end

#put?Boolean

returns true of the method == PUT

Returns:

  • (Boolean)

90
91
92
# File 'lib/anorexic/server/protocols/http_request.rb', line 90

def put?
	self[:method] == 'PUT'
end

#queryObject

the query string


40
41
42
# File 'lib/anorexic/server/protocols/http_request.rb', line 40

def query
	self[:query]
end

#request_methodObject

the request's method (GET, POST… etc').


23
24
25
# File 'lib/anorexic/server/protocols/http_request.rb', line 23

def request_method
	self[:method]
end

#request_method=(value) ⇒ Object

set request's method (GET, POST… etc').


27
28
29
# File 'lib/anorexic/server/protocols/http_request.rb', line 27

def request_method= value
	self[:method] = value
end

#serviceObject

the service (socket wrapper) that answered this request


63
64
65
# File 'lib/anorexic/server/protocols/http_request.rb', line 63

def service
	self[:anorexic_service]
end

#trace?Boolean

returns true of the method == TRACE

Returns:

  • (Boolean)

98
99
100
# File 'lib/anorexic/server/protocols/http_request.rb', line 98

def trace?
	self[:method] == 'TRACE'
end