On Wed, May 13, 2009 at 01:40:10PM +0200, Alexander M??ller wrote:
>
> Hi,
>
> I am trying to come up with a Reverse Proxy using HttpCore, however came
> across some difficulties and hope someone here could point me into the right
> direction.
>
> Basically I am having a servlet putting all of the received headers into a
> BasicHttpRequest instance, which it then sends with sendRequestHeaders(). So
> far this would work, however once I try to get the response by
> receiveResponseHeader() it simply stalls at
> AbstractSessionInputBuffer.fillBuffer() upon reading from instream. This
> would make me believe the server hasnt yet sent any response - most probably
> because it didnt yet receive the full request. I could confirm the latter
> partly when I tried to send the request manually (via the socket's output
> stream) as I could then receive the response successfully. Furthermore it
> also seems to work by not using sendRequestHeader() and
> receiveResponseHeader() but instead a HttpRequestExecutor.
>
> My assumption would be that something about sending the request is not right
> yet, but I couldnt say what. Below is an a bit trimmed down version, did I
> miss something?
>
> HttpRequest req=null;
> req=new BasicHttpRequest(request.getMethod(),
> "path-to-connect-to");
>
> for (Enumeration<String> e=request.getHeaderNames();
> e.hasMoreElements(); )
> {
> String header=e.nextElement();
>
> for (Enumeration<String> _e=request.getHeaders(header);
> _e.hasMoreElements(); )
> req.addHeader(header, _e.nextElement());
> }
>
> Socket socket=new Socket('hostname', 80);
>
> DefaultHttpClientConnection con=new DefaultHttpClientConnection();
> con.bind(socket, new BasicHttpParams());
>
> con.sendRequestHeader(req);
>
> HttpResponse resp=con.receiveResponseHeader();
>
> response.setStatus(resp.getStatusLine().getStatusCode());
>
>
> Thanks for any help,
> Alexander
>
Hi Alexander
This is approach is obviously wrong because it does not take into account so
called hop-by-hop headers. Proxies should not blindly copy all request headers
of the incoming request to the outgoing request. This can lead to incorrect
delimitation of the message content body.
Please refer to the sample reverse proxy shipped with HttpCore for an example
of hop-by-hop header handling.
http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalReverseProxy.java
Let me know if that resolves the issue for you.
Oleg
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]