Class: Rbkb::Http::RequestAction
- Inherits:
-
Object
- Object
- 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.
315 316 317 318 319 320 |
# File 'lib/rbkb/http/headers.rb', line 315 def initialize(*args) _common_init(*args) @verb ||= "GET" @uri ||= URI.parse("/") @version ||= "HTTP/1.0" end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
357 358 359 |
# File 'lib/rbkb/http/headers.rb', line 357 def base @base end |
#uri ⇒ Object
Returns the value of attribute uri.
313 314 315 |
# File 'lib/rbkb/http/headers.rb', line 313 def uri @uri end |
#verb ⇒ Object
Returns the value of attribute verb.
313 314 315 |
# File 'lib/rbkb/http/headers.rb', line 313 def verb @verb end |
#version ⇒ Object
Returns the value of attribute version.
313 314 315 |
# File 'lib/rbkb/http/headers.rb', line 313 def version @version end |
Class Method Details
.parse(str) ⇒ Object
309 310 311 |
# File 'lib/rbkb/http/headers.rb', line 309 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.
329 330 331 332 333 334 335 336 337 338 |
# File 'lib/rbkb/http/headers.rb', line 329 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.
353 354 355 |
# File 'lib/rbkb/http/headers.rb', line 353 def parameters FormUrlencodedParams.parse(query) if query end |
#path ⇒ Object
Returns the URI path as a String if defined
341 342 343 |
# File 'lib/rbkb/http/headers.rb', line 341 def path @uri.path if @uri end |
#query ⇒ Object
Returns the URI query as a String if it is defined
346 347 348 |
# File 'lib/rbkb/http/headers.rb', line 346 def query @uri.query if @uri end |
#to_raw ⇒ Object
322 323 324 325 326 |
# File 'lib/rbkb/http/headers.rb', line 322 def to_raw ary = [ @verb, @uri ] ary << @version if @version ary.join(" ") end |