Class: RAWS::HTTP::HT2P::Request

Inherits:
Request
  • Object
show all
Defined in:
lib/raws/http/ht2p.rb

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ Request

Returns a new instance of Request.



19
20
21
# File 'lib/raws/http/ht2p.rb', line 19

def initialize(request)
  @request, @before_send = request, nil
end

Instance Method Details

#before_send(&block) ⇒ Object



35
36
37
# File 'lib/raws/http/ht2p.rb', line 35

def before_send(&block)
  @before_send = block
end

#headerObject



31
32
33
# File 'lib/raws/http/ht2p.rb', line 31

def header
  @request.header
end

#methodObject



23
24
25
# File 'lib/raws/http/ht2p.rb', line 23

def method
  @request.method
end

#method=(val) ⇒ Object



27
28
29
# File 'lib/raws/http/ht2p.rb', line 27

def method=(val)
  @request.method = val
end

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



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/raws/http/ht2p.rb', line 39

def send(body=nil, &block)
  RAWS.logger.debug self
  @before_send && @before_send.call(self)
  response = Response.new(@request.send(body, &block))
  case response.code
  when 200...300
    response
  when 300...400
    response.parse
    raise RAWS::HTTP::Redirect.new(response)
  else
    response.parse
    raise RAWS::HTTP::Error.new(response)
  end
end