Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Adding custom header into HttpServletRequest

Awesome, thanks! This works perfectly fine with me. Thanks a ton, @Joakim Erdfelt 

Best,
Aniruddha
========


On Tue, Jul 6, 2021 at 3:06 PM Joakim Erdfelt <joakim@xxxxxxxxxxx> wrote:
Ah, I missed that you were on Jetty 11.

The request.getHttpFields() is an immutable object starting in Jetty 10.0.0.

No worries, do this ...

HttpFields.Mutable replacement = HttpFields.build(request.getHttpFields())
.put("X-Request-ID", UUID.randomUUID().toString().toUpperCase());
request.setHttpFields(replacement);

Joakim Erdfelt / joakim@xxxxxxxxxxx


On Tue, Jul 6, 2021 at 5:00 PM Aniruddha Tekade <atekade@xxxxxxxxxxxx> wrote:
Hi all,

I actually posted this question on stackoverflow earlier. I am using Jetty 11 and I am trying to add a custom header into httpServletRequest in my handler class. 

Thanks to @Joakim Erdfelt for introducing me to HttpChannel.Listener. I followed his solution from stack-overflow comment but stuck at finding the put() method. Here are my details:
  1. I created a class RequestChannelListener implements HttpChannel.Listener
  2. Created an instance of this class
  3. Added as bean into connector in main method of the project
  4. Within RequestChannelListener - I implemented method onRequestBegin(Request request) and used this - 
public class RequestChannelListener implements HttpChannel.Listener {
@Override
public void onRequestBegin(Request request) {
request.getHttpFields().put("X-Request-ID", UUID.randomUUID().toString().toUpperCase());
}
}
But I am not able to find the put method. Any suggestions?


Best,
Aniruddha
========

Back to the top