You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Oleg Kalnichevski (JIRA)" <ji...@apache.org> on 2013/08/02 13:23:49 UTC

[jira] [Resolved] (HTTPCORE-337) Example Fix: NIO Reverse Proxy Server Example

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

Oleg Kalnichevski resolved HTTPCORE-337.
----------------------------------------

       Resolution: Won't Fix
    Fix Version/s:     (was: 4.3)
    
> 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
>
> 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