Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 0390b4240c
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 58 lines (47 sloc) 1.555 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
require 'net/http'
require 'net/https'
require 'stringio'

module Net #:nodoc: all

  class BufferedIO
    def initialize(io, debug_output = nil)
      @read_timeout = 60
      @rbuf = ''
      @debug_output = debug_output

      @io = case io
      when Socket, OpenSSL::SSL::SSLSocket, IO
        io
      when String
        File.exists?(io) ? File.open(io, "r") : StringIO.new(io)
      end
      raise "Unable to create local socket" unless @io
    end
  end

  class HTTP
    def self.socket_type
      FakeWeb::SocketDelegator
    end

    alias :original_net_http_request :request
    alias :original_net_http_connect :connect

    def request(request, body = nil, &block)
      protocol = use_ssl ? "https" : "http"

      path = request.path
      path = URI.parse(request.path).request_uri if request.path =~ /^http/

      uri = "#{protocol}://#{self.address}:#{self.port}#{path}"
      method = request.method.downcase.to_sym

      if registered = FakeWeb::Registry.instance.registered_uri(method, uri)
        responder = FakeWeb::Registry.instance.send(:pick_responder, registered)
        responder.verify(request)
        @socket = Net::HTTP.socket_type.new
        responder.response(&block)
      elsif FakeWeb.allow_net_connect?
        original_net_http_connect
        original_net_http_request(request, body, &block)
      else
        raise FakeWeb::NetConnectNotAllowedError,
              "Real HTTP connections are disabled. Unregistered request: #{request.method} #{uri}"
      end
    end

    def connect
    end
  end

end
Something went wrong with that request. Please try again.