hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oleg Kalnichevski (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (HTTPCORE-337) Example Fix: NIO Reverse Proxy Server Example
Date Thu, 25 Apr 2013 11:56:16 GMT

     [ https://issues.apache.org/jira/browse/HTTPCORE-337?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Oleg Kalnichevski updated HTTPCORE-337:
---------------------------------------

    Fix Version/s: 4.3-beta2

Mike

If we want to pass headers from the incoming request to the origin server then we should remove
all hop-by-hop headers, not just 'content-length', 'transfer-encoding' and 'connection'. See
how it is done in the blocking version of the reverse proxy.

https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalReverseProxy.java

Could you please attach your patch to the issue instead of posting it in-line?

Oleg
                
> Example Fix: NIO Reverse Proxy Server Example
> ---------------------------------------------
>
>                 Key: HTTPCORE-337
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-337
>             Project: HttpComponents HttpCore
>          Issue Type: Bug
>          Components: Examples
>    Affects Versions: 4.2.4
>            Reporter: Mike Corneille
>            Priority: Minor
>             Fix For: 4.3-beta2
>
>
> Problem: The 302 redirect doesn't work because the "location" header isn't properly transposed.
By copying all headers from the origin to the client respolves the 302 problem.  There could
be other issues with simply transposing all headers, but this is a good fix to add for now...
> Examples found on page:
> http://hc.apache.org/httpcomponents-core-ga/examples.html
> http://hc.apache.org/httpcomponents-core-ga/httpcore-nio/examples/org/apache/http/examples/nio/NHttpReverseProxy.java
> +import org.apache.http.Header;
>  import org.apache.http.HttpResponse;
>  import org.apache.http.message.BasicHttpResponse;
>  import org.apache.http.nio.ContentEncoder;
> @@ -46,6 +47,11 @@ class ProxyResponseProducer implements HttpAsyncResponseProducer
>              // Rewrite response!!!!
>              BasicHttpResponse r = new BasicHttpResponse(response.getStatusLine());
>  
> +            Header[] headers = response.getAllHeaders();
> +            for (Header header: headers)
> +            {
> +                if (!header.getName().toLowerCase().equals("transfer-encoding") &&
!header.getName().toLowerCase().equals("content-length")
> +                    && !header.getName().toLowerCase().equals("connection"))
> +                {
> +                    r.addHeader(header);
> +                }
> +            }
>              r.setEntity(response.getEntity());
>              return r;
>          }
> @@ -118,4 +137,4 @@ class ProxyRequestProducer implements HttpAsyncRequestProducer
> +                    if (!header.getName().toLowerCase().equals("host") && !header.getName().toLowerCase().equals("content-length"))
> +                    {
> +                        r.addHeader(header);
> +                    }
> +                }
> +
>                  r.setEntity(((HttpEntityEnclosingRequest) request).getEntity());
>                  return r;
>              }
>              else
>              {
> -                return new BasicHttpRequest(request.getRequestLine());
> +                BasicHttpRequest r = new BasicHttpRequest(request.getRequestLine());
> +                Header[] headers = request.getAllHeaders();
> +                for (Header header: headers)
> +                {
> +                    if (!header.getName().toLowerCase().equals("host") && !header.getName().toLowerCase().equals("content-length"))
> +                    {
> +                        r.addHeader(header);
> +                    }
> +                }
> +
> +                return r;
>              }
>          }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Mime
View raw message