chrisk/fakeweb — pull request #44 by dylanahsmith (2014-01-09 00:32:04+00:00)
Title: Fix reconnect on keep allow timeout for passthrough uris.

Depends on pull #43 and includes the commit from that pull request. See the second commit for the changes for this pull request.

## Problem

pull #43 fixes the following problem when remove connections are allowed to any URI, but not when passthrough uris are registered

> Ruby 2.0 added a keep_alive_timeout variable to Net::HTTP for persistent. If keep_alive_timeout seconds has passed between requests, then Net::HTTP will close the socket and call connect. However, fakeweb replaces the connect method to have it do nothing (delaying it until request is called), so the socket is closed without reconnecting on a keep_alive_timeout.

## Solution

In this case, it would be preferred to delay the `connect` on Net::HTTP.start until the `request` method is called, since fakeweb is in use and we don't want to connect to a remote server when all the requests the a connection will be mocked. However, we want a `connect` to work inside of `request_without_fakeweb` due to a keep alive timeout or retry logic.

To accomplish this, I set and reset an instance variable around the call to `request_without_fakeweb`, then have the `connect` method actually connect to the remote server if this variable set.