[undertow-dev] Changing headers on proxy response

Stuart Douglas sdouglas at redhat.com
Mon Nov 3 02:57:48 EST 2014


You just return the original conduit, but set the headers in the wrapper class itself. 

Stuart

----- Original Message -----
> From: "Jeff Williams" <jeffw at wherethebitsroam.com>
> To: "Stuart Douglas" <sdouglas at redhat.com>
> Cc: undertow-dev at lists.jboss.org
> Sent: Monday, 3 November, 2014 6:34:28 PM
> Subject: Re: [undertow-dev] Changing headers on proxy response
> 
> Stuart,
> 
> Thanks for that. I'm guessing I can just extend
> org.xnio.conduits.AbstractStreamSinkConduit<StreamSinkConduit> and just
> pass everything through to next? Since there is not much information around
> about the StreamSinkConduit, where would be the best place to add the
> headers? In the first call to one of the transferFrom methods?
> 
> I've added a JIRA for this: https://issues.jboss.org/browse/UNDERTOW-340
> 
> Regards,
> Jeff
> 
> On 2 November 2014 04:24, Stuart Douglas <sdouglas at redhat.com> wrote:
> 
> > You can set them in a response wrapper
> > (io.undertow.server.HttpServerExchange#addResponseWrapper) and they should
> > not be overriden, although this is not ideal.
> >
> > If you file a JIRA I will look at adding better support for this into the
> > proxy.
> >
> > Stuart
> >
> > ----- Original Message -----
> > > From: "Jeff Williams" <jeffw at wherethebitsroam.com>
> > > To: undertow-dev at lists.jboss.org
> > > Sent: Saturday, 1 November, 2014 12:43:38 AM
> > > Subject: [undertow-dev] Changing headers on proxy response
> > >
> > > Hi,
> > >
> > > I am currently using a customer handler wrapping the proxy handler. I
> > want to
> > > set some response headers from my handler, but if they exist in the
> > response
> > > from the proxy's backend, they are overridden. Example code:
> > >
> > > Undertow.builder()
> > > .addHttpListener(8080, "localhost")
> > > .setHandler(new MyHandler(new ProxyHandler(proxy, 30000,
> > ResponseCodeHandler.
> > > HANDLE_404 ))).build();
> > >
> > > class MyHandler extends HttpHandler {
> > > private static final HttpString ACCESS_CONTROL_EXPOSE_HEADERS = new
> > > HttpString("Access-Control-Expose-Headers");
> > > private HTTPHandler next;
> > > public MyHandler(HttpHandler next) {
> > > this.next = next;
> > > }
> > > p ublic void handleRequest(HttpServerExchange exchange ) throws
> > Exception {
> > > exchange .getResponseHeaders().put( ACCESS_CONTROL_EXPOSE_HEADERS , " new
> > > ACEH" );
> > > }
> > > }
> > >
> > > The problem here is that the backend server responds with an
> > > Access-Control-Expose-Headers header and that replaces the one I set in
> > > MyHandler.
> > >
> > > Is there any way I can change headers after proxy has received the
> > response
> > > from backend and before it starts sending the response to the client?
> > >
> > > Regards,
> > > Jeff
> > >
> > >
> > > _______________________________________________
> > > undertow-dev mailing list
> > > undertow-dev at lists.jboss.org
> > > https://lists.jboss.org/mailman/listinfo/undertow-dev
> >
> 


More information about the undertow-dev mailing list