Class: ThreadedProxy::HTTP

Inherits:
Net::HTTP
  • Object
show all
Defined in:
lib/threaded_proxy/http.rb

Instance Method Summary collapse

Instance Method Details

#copy_to(dest_socket) ⇒ Object



17
18
19
# File 'lib/threaded_proxy/http.rb', line 17

def copy_to(dest_socket)
  IO.copy_stream(@socket.io, dest_socket)
end

#flush_existing_buffer_to(dest_socket) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/threaded_proxy/http.rb', line 7

def flush_existing_buffer_to(dest_socket)
  while (data = @socket.send(:rbuf_consume))
    break if data.empty?

    dest_socket.write data
  end

  dest_socket.flush
end

#request(*args) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/threaded_proxy/http.rb', line 21

def request(*args)
  if block_given?
    super do |res|
      access_read(res)
      yield(res).tap do
        # In the block case, the response is hijacked _after_ the block is called
        # to allow the block to read the response body if it wants
        hijack_response(res)
      end
    end
  else
    hijack_response(super)
  end
end