close socket on error

There are cases where a request can not be idempotent (when a
request_block is used) or using the idempotent middleware is not
desired. This ensures the socket is closed if the error is rescued and
the request is retried.

This also prevents an issue with the test suite, where a test can fail
and subsequent tests will fail because they receive the response body
from the previous test's request, or 'bad write retry' errors occur.
remove defense mechanism in Socket#write

Removes the check for IO#write_nonblock returning more bytes written
than requested. This was a result of an encoding issue (#271).
Merge pull request #273 from burns/close_socket

close socket on error
Merge pull request #274 from burns/remove_defense_mechanism

remove defense mechanism in Socket#write
use StringIO to process String request body

This solves an Encoding compatibility issue (#266) with concatenating
the request and body. Also solves an issue with ruby-1.8.7 when using a
large string body, as the socket writes are now chunked.
close socket to fix test under 1.9.2