Sha256: 853a8ca95018ff47869f0ba3526ed1e1a25321b008e403ed5387731548bbd9d6

Contents?: true

Size: 707 Bytes

Versions: 2

Compression:

Stored size: 707 Bytes

Contents

require 'net/http'

module ThreadedProxy
  class HTTP < Net::HTTP
    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

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

    def request(*args)
      if block_given?
        super { |res| yield hijack_response(res) }
      else
        hijack_response(super)
      end
    end

    protected

    # We read the response ourselves; don't need net/http to try to read it again
    def hijack_response(res)
      res.instance_variable_set("@read", true)
      res
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rails-threaded-proxy-0.2.0 lib/threaded_proxy/http.rb
rails-threaded-proxy-0.1.0 lib/threaded_proxy/http.rb