Adding HTTP Response Header [message #728547] |
Fri, 23 September 2011 09:12  |
Eclipse User |
|
|
|
Hi, I would like to add some HTTP headers to the initial response that is sent by the servlet that renders my RAP application. In particular, I mean the servlet whose name is configured by the 'servletName' attribute of the org.eclipse.rap.ui.branding extension point.
I tried to call
RWT.getResponse().setHeader("xzy-header", "header-value"); before the 'Prepare UI Root' phase by registering a PhaseListener via the org.eclipse.rap.ui.phaselistener extension point.
However, my call comes too late: by then the servlet has already sent its response and the browser has received it accordingly (without the xzy-header).
Any idea on how to add the headers before the servlet sends its response?
Thank you!
|
|
|
|
|
Re: Adding HTTP Response Header [message #728673 is a reply to message #728586] |
Fri, 23 September 2011 12:14  |
Eclipse User |
|
|
|
>> I am not quite sure which request you mean.
I mean the response that my browser receives for its HTTP request to
http://myhost.com:1234/myServletName?startup=myExtensionPoint where "myServletName" is the one specified in the 'servletName' attribute of the org.eclipse.rap.ui.branding extension point.
>> You can use servlet filters in order to manipulate
>> any request that is processed by the servlet.
Great hint, thx! Now I solved my problem by using the org.eclipse.equinox.http.registry.filters extension point: I filter on the alias '/myServletName' and added the following code to the Filter#doFilter(ServletRequest, ServletResponse, FilterChain) method:
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.setHeader("Xzy-header", "header-value");
chain.doFilter(request, response);
>> Just out of curiosity, why do you need custom HTTP headers?
For an internal demo application, we forward users from one web server to another web server. As such behavior is interpreted by state of the art browsers as cross site scripting attack violating the same origin policy, I needed to explicitly allow this behavior by using the 'Access-Control-Allow-Origin' header field.
|
|
|
Powered by
FUDForum. Page generated in 0.03523 seconds