Class: HT2P::Client::Request

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ht2p/client/request.rb

Constant Summary collapse

METHODS =
%w'get head post put delete options trace connect'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, params) ⇒ Request

Returns a new instance of Request.



10
11
12
13
14
# File 'lib/ht2p/client/request.rb', line 10

def initialize(client, params)
  @client = client
  @method = params[:method] || :get
  @header = HT2P::Header.new.merge!(params[:header] || {})
end

Instance Attribute Details

#headerObject Also known as: headers

Returns the value of attribute header.



6
7
8
# File 'lib/ht2p/client/request.rb', line 6

def header
  @header
end

#methodObject

Returns the value of attribute method.



6
7
8
# File 'lib/ht2p/client/request.rb', line 6

def method
  @method
end

Instance Method Details

#send(body = nil, &block) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/ht2p/client/request.rb', line 16

def send(body=nil, &block)
  @header['content-length'] = body.to_s.size if body
  @client.write @header.format(@method, @client.uri)
  @client.write body if body
  block.call self if block_given?
  @client.flush
  HT2P::Client::Response.new @client
end