Class: Rbkb::Http::RequestAction

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CommonInterface

#_common_init, #opts, #opts=

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

#baseObject

Returns the value of attribute base.



357
358
359
# File 'lib/rbkb/http/headers.rb', line 357

def base
  @base
end

#uriObject

Returns the value of attribute uri.



313
314
315
# File 'lib/rbkb/http/headers.rb', line 313

def uri
  @uri
end

#verbObject

Returns the value of attribute verb.



313
314
315
# File 'lib/rbkb/http/headers.rb', line 313

def verb
  @verb
end

#versionObject

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

#parametersObject

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

#pathObject

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

#queryObject

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_rawObject



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