{
/*
* Note: we won't transfer the protocol version because I'm not sure it would truly be compatible
*/
String method = servletRequest.getMethod();
HttpRequest proxyRequest;
/*
* Spec: RFC 2616, sec 4.3: either of these two headers signal that there is a message body.
*/
if (servletRequest.getHeader(HttpHeaders.CONTENT_LENGTH) != null ||
servletRequest.getHeader(HttpHeaders.TRANSFER_ENCODING) != null)
{
HttpEntityEnclosingRequest eProxyRequest = new BasicHttpEntityEnclosingRequest(method, targetUri);
/*
* Add the input entity (streamed) note: we don't bother ensuring we close the servletInputStream since the
* container handles it
*/
eProxyRequest.setEntity(new InputStreamEntity(servletRequest.getInputStream(), servletRequest
.getContentLength()));
proxyRequest = eProxyRequest;
}
else
proxyRequest = new BasicHttpRequest(method, targetUri);
copyRequestHeaders(servletRequest, proxyRequest);
try
{
/*
* Execute the request
*/
if (doLog)
{
logger.debug("proxy " + method + " uri: " + servletRequest.getRequestURI() + " -- "
+ proxyRequest.getRequestLine().getUri());
}
HttpResponse proxyResponse = proxyClient.execute(URIUtils.extractHost(targetUriObj), proxyRequest);
/*
* Process the response