final HttpMethodBase httpMethod = createHttpMethod(uri, request.getHttpMethod());
loadHttpMethod(request, httpMethod);
int status = httpClient.executeMethod(httpMethod);
BaseClientResponse response = new BaseClientResponse(new BaseClientResponseStreamFactory()
{
InputStream stream;
public InputStream getInputStream() throws IOException
{
if (stream == null)
{
stream = new SelfExpandingBufferredInputStream(httpMethod.getResponseBodyAsStream());
}
return stream;
}
public void performReleaseConnection()
{
try
{
httpMethod.releaseConnection();
}
catch (Exception ignored) {}
try
{
stream.close();
}
catch (Exception ignored) {}
}
});
response.setStatus(status);
response.setHeaders(extractHeaders(httpMethod));
response.setProviderFactory(request.getProviderFactory());
return response;
}