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

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



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

- (Object) body (readonly)

Returns the value of attribute body



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

def body
  @body
end

- (Object) headers (readonly)

Returns the value of attribute headers



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

def headers
  @headers
end

- (Object) http_method (readonly)

Returns the value of attribute http_method



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

def http_method
  @http_method
end

- (Object) http_version (readonly)

Returns the value of attribute http_version



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

def http_version
  @http_version
end

- (Object) uri (readonly)

Returns the value of attribute uri



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

def uri
  @uri
end

Instance Method Details

- (Boolean) body_included?



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

def body_included?
  body_present?
end

- (Boolean) body_present?



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

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

- (Object) new_self(args)



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

- (Object) sequence(obj, id = nil)



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

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

- (Object) with(index, argument)



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

- (Object) with_body(new_body)



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

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

- (Object) with_headers(new_headers)



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

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