Class: WhackANode::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/whack_a_node/proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(path = "/", host = "localhost", port = "8810") ⇒ Proxy

Returns a new instance of Proxy.



5
6
7
8
9
# File 'lib/whack_a_node/proxy.rb', line 5

def initialize(path="/",host="localhost", port="8810")
  @path = path
  @host = host
  @port = port
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/whack_a_node/proxy.rb', line 11

def call(env)
  uri = self.uri
  session = Net::HTTP.new(uri.host, uri.port)
  session.start {|http|
    req = Net::HTTP::Get.new(uri.request_uri)
    body = ''
    res = http.request(req) do |res|
      res.read_body do |segment|
        body << segment
      end
    end

    [res.code, create_response_headers(res), [body]]
    }
  
end

#uriObject



28
29
30
# File 'lib/whack_a_node/proxy.rb', line 28

def uri
  URI("http://#{@host}:#{@port}#{@path}")
end