Class: HTTPkit::Request

Inherits:
Object
  • Object
show all
Includes:
Adamantium, Support::Message
Defined in:
lib/httpkit/request.rb

Constant Summary

SequenceHash =
Class.new(Hash) { include Adamantium::Mutable }

Constants included from Support::Message

Support::Message::CHUNKED, Support::Message::CONTENT_LENGTH, Support::Message::TRANSFER_ENCODING

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Support::Message

#body_headers, build, #close, #closed, #closed!, #closed?, #reject_closed

Constructor Details

#initialize(http_method, uri, headers = {}, body = '', http_version = 1.1) ⇒ Request



10
11
12
13
14
15
16
17
18
19
# File 'lib/httpkit/request.rb', line 10

def initialize(http_method, uri, headers = {}, body = '',
               http_version = 1.1)
  @http_method = http_method
  # @uri = URI('http://' + uri)
  @uri = URI.join('http:///', uri).request_uri
  @headers = headers
  @body = Body.build(body)
  @http_version = http_version
  @sequences = SequenceHash.new
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body



8
9
10
# File 'lib/httpkit/request.rb', line 8

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers



8
9
10
# File 'lib/httpkit/request.rb', line 8

def headers
  @headers
end

#http_methodObject (readonly)

Returns the value of attribute http_method



8
9
10
# File 'lib/httpkit/request.rb', line 8

def http_method
  @http_method
end

#http_versionObject (readonly)

Returns the value of attribute http_version



8
9
10
# File 'lib/httpkit/request.rb', line 8

def http_version
  @http_version
end

#uriObject (readonly)

Returns the value of attribute uri



8
9
10
# File 'lib/httpkit/request.rb', line 8

def uri
  @uri
end

Instance Method Details

#body_included?Boolean



45
46
47
# File 'lib/httpkit/request.rb', line 45

def body_included?
  body_present?
end

#body_present?Boolean



49
50
51
# File 'lib/httpkit/request.rb', line 49

def body_present?
  !body.length_known? || !body.length.zero?
end

#new_self(args) ⇒ Object



35
36
37
38
39
# File 'lib/httpkit/request.rb', line 35

def new_self(args)
  other = self.class.new(*args)
  @sequences.each { |(obj, id)| other.sequence(obj, id) }
  other
end

#sequence(obj, id = nil) ⇒ Object



41
42
43
# File 'lib/httpkit/request.rb', line 41

def sequence(obj, id = nil)
  @sequences[obj.object_id] ||= id
end

#with(index, argument) ⇒ Object



29
30
31
32
33
# File 'lib/httpkit/request.rb', line 29

def with(index, argument)
  args = [http_method, uri, headers, body, http_version]
  args[index] = argument
  new_self(args)
end

#with_body(new_body) ⇒ Object



25
26
27
# File 'lib/httpkit/request.rb', line 25

def with_body(new_body)
  with(3, Body.build(new_body))
end

#with_headers(new_headers) ⇒ Object



21
22
23
# File 'lib/httpkit/request.rb', line 21

def with_headers(new_headers)
  with(2, headers.merge(new_headers))
end