Class: Rbkb::Http::RequestAction
- Includes:
- CommonInterface
- Defined in:
- lib/rbkb/http/headers.rb
Overview
A class for HTTP request actions, i.e. the first header sent in an HTTP request, as in “GET / HTTP/1.1”
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
-
#uri ⇒ Object
Returns the value of attribute uri.
-
#verb ⇒ Object
Returns the value of attribute verb.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
-
#capture(str) ⇒ Object
This method parses a request action String into the current instance.
-
#initialize(*args) ⇒ RequestAction
constructor
A new instance of RequestAction.
-
#parameters ⇒ Object
Returns the URI query parameters as a FormUrlencodedParams object if the query string is defined.
-
#path ⇒ Object
Returns the URI path as a String if defined.
-
#query ⇒ Object
Returns the URI query as a String if it is defined.
- #to_raw ⇒ Object
Methods included from CommonInterface
Constructor Details
#initialize(*args) ⇒ RequestAction
Returns a new instance of RequestAction.
280 281 282 283 284 285 |
# File 'lib/rbkb/http/headers.rb', line 280 def initialize(*args) _common_init(*args) @verb ||= "GET" @uri ||= URI.parse("/") @version ||= "HTTP/1.1" end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
322 323 324 |
# File 'lib/rbkb/http/headers.rb', line 322 def base @base end |
#uri ⇒ Object
Returns the value of attribute uri.
278 279 280 |
# File 'lib/rbkb/http/headers.rb', line 278 def uri @uri end |
#verb ⇒ Object
Returns the value of attribute verb.
278 279 280 |
# File 'lib/rbkb/http/headers.rb', line 278 def verb @verb end |
#version ⇒ Object
Returns the value of attribute version.
278 279 280 |
# File 'lib/rbkb/http/headers.rb', line 278 def version @version end |
Class Method Details
.parse(str) ⇒ Object
274 275 276 |
# File 'lib/rbkb/http/headers.rb', line 274 def self.parse(str) new().capture(str) end |
Instance Method Details
#capture(str) ⇒ Object
This method parses a request action String into the current instance.
294 295 296 297 298 299 300 301 302 303 |
# File 'lib/rbkb/http/headers.rb', line 294 def capture(str) raise "arg 0 must be a string" unless str.is_a?(String) unless m=/^([^\s]+)\s+([^\s]+)(?:\s+([^\s]+))?\s*$/.match(str) raise "invalid action #{str.inspect}" end @verb = m[1] @uri = URI.parse m[2] @version = m[3] return self end |
#parameters ⇒ Object
Returns the URI query parameters as a FormUrlencodedParams object if the query string is defined. XXX note parameters cannot currently be modified in this form.
318 319 320 |
# File 'lib/rbkb/http/headers.rb', line 318 def parameters FormUrlencodedParams.parse(query) if query end |
#path ⇒ Object
Returns the URI path as a String if defined
306 307 308 |
# File 'lib/rbkb/http/headers.rb', line 306 def path @uri.path if @uri end |
#query ⇒ Object
Returns the URI query as a String if it is defined
311 312 313 |
# File 'lib/rbkb/http/headers.rb', line 311 def query @uri.query if @uri end |
#to_raw ⇒ Object
287 288 289 290 291 |
# File 'lib/rbkb/http/headers.rb', line 287 def to_raw ary = [ @verb, @uri ] ary << @version if @version ary.join(" ") end |