Class: Rbkb::Http::Request

Inherits:
Base show all
Defined in:
lib/rbkb/http/request.rb

Overview

A Request encapsulates all the entities in a HTTP request message including the action header, general headers, and body.

Instance Attribute Summary collapse

Attributes inherited from Base

#body, #headers

Instance Method Summary collapse

Methods inherited from Base

#attach_new_body, #attach_new_header, #capture_body, #capture_complete?, #capture_headers, #content_length, #initialize, parse, #reset_capture, #reset_capture!

Methods included from CommonInterface

#_common_init, #opts, #opts=

Constructor Details

This class inherits a constructor from Rbkb::Http::Base

Instance Attribute Details

#actionObject Also known as: first_entity

Returns the value of attribute action.



6
7
8
# File 'lib/rbkb/http/request.rb', line 6

def action
  @action
end

Instance Method Details

#capture(str) ⇒ Object

Parses a raw HTTP request and captures data into the current instance.



49
50
51
52
53
54
55
56
# File 'lib/rbkb/http/request.rb', line 49

def capture(str)
  raise "arg 0 must be a string" unless String === str
  hstr, bstr = str.split(/\s*\r?\n\r?\n/, 2)
  capture_headers(hstr)
  self.body = content_length ? BoundBody.new : Body.new
  capture_body(bstr)
  return self
end

#default_body_obj(*args) ⇒ Object

Returns a new BoundBody object. This is the default object which will be used when composing fresh Request body entities.



24
25
26
# File 'lib/rbkb/http/request.rb', line 24

def default_body_obj(*args)
  Body.new(*args)
end

#default_headers_obj(*args) ⇒ Object

Returns a new Headers object extended as RequestHeaders. This is the default object which will be used when composing fresh Request header entities.



18
19
20
# File 'lib/rbkb/http/request.rb', line 18

def default_headers_obj(*args)
  Headers.new(*args).extend(RequestHeaders)
end

#request_parametersObject



11
12
13
# File 'lib/rbkb/http/request.rb', line 11

def request_parameters
  @action.parameters
end

#to_raw(tmp_body = @body) ⇒ Object

Returns a raw HTTP request for this instance. The instance must have an action element defined at the bare minimum.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rbkb/http/request.rb', line 30

def to_raw(tmp_body=@body)
  raise "this request has no action entity" unless first_entity()
  self.headers ||= default_headers_obj()
  self.body ||= default_body_obj()

  if len=@opts[:static_length]
    @body = Body.new(@body, @body.opts) {|x| x.base = self}
    @headers.set_header("Content-Length", len.to_i)
  elsif @opts[:ignore_content_length]
    @headers.delete_header("Content-Length")
  end

  bstr = tmp_body.to_raw
  hdrs = (@headers).to_raw_array.unshift(first_entity.to_raw)
  return "#{hdrs.join("\r\n")}\r\n\r\n#{bstr}"
end