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.



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

#baseObject

Returns the value of attribute base.



322
323
324
# File 'lib/rbkb/http/headers.rb', line 322

def base
  @base
end

#uriObject

Returns the value of attribute uri.



278
279
280
# File 'lib/rbkb/http/headers.rb', line 278

def uri
  @uri
end

#verbObject

Returns the value of attribute verb.



278
279
280
# File 'lib/rbkb/http/headers.rb', line 278

def verb
  @verb
end

#versionObject

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

#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.



318
319
320
# File 'lib/rbkb/http/headers.rb', line 318

def parameters
  FormUrlencodedParams.parse(query) if query
end

#pathObject

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

#queryObject

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_rawObject



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