I am trying to customize the response of a bayeux server response so that i can add some header parameters before sending it back to UI. I am able to add header values in the request using customize method in a LongPollingTransport. Much help needed.
1 Answers
CometD tries to abstract away from the underlying protocol.
When you use WebSocket
, for example, the concepts of request headers and response headers simply do not exist anymore.
As such, it is way better that if you have additional information to send to the client, well that additional information should go in the CometD messages rather than in HTTP headers.
Furthermore, when using HTTP as a transport, a single HTTP response may carry multiple messages, so it is not clear to what CometD message the additional information would refer to.
Your question is too generic (does not say why you want to add headers, does not say what specific header, etc.) to get a precise answer, but bottom line is that you typically don't want to use HTTP headers with CometD.

- 16,856
- 1
- 50
- 45
-
The additional information i want to add to the headers is completely security related for e.g. set X-Frame-Options: DENY, "add Cache-Control: no-cache, no-store, must-revalidate", etc. But If i add it to the message it will part of the body (please correct me If I am wrong). – rahul Aug 21 '17 at 06:52
-
Can't you use a Servlet Filter to do that ? – sbordet Aug 21 '17 at 10:04
-
Yes, I have used HeaderFilter in jetty distribution to do that which I have configured in my web.xml file as mentioned here http://www.eclipse.org/jetty/documentation/9.4.x/header-filter.html but for normal http responses i can set the headers but for the cometD responses it is not setting it. Could you please give me an example of how to do that. I am using cometd js library and that makes the request to the bayeux server. Is this the reason it does not intercept it? – rahul Aug 21 '17 at 10:55
-
File an issue at https://github.com/cometd/cometd/issues and let's continue the discussion there. – sbordet Aug 21 '17 at 14:07
-
I was able to do it using custom filter. Thanks for your help Simon. – rahul Aug 22 '17 at 06:18