Search code examples
servletsnetflix-zuul

How to Manually Change the Request URL of an HttpServletRequest


I have a Zuul server running in front of a web server. A part of the web server that I am unable to change is calling the method getRequestURL() on my HttpServletRequest object. As part of a pre-routing filter on the Zuul server I would like to modify the requestURL of this HttpServletRequest. How can I do that?

My code that I'm working from looks like this so far:

RequestContext context = RequestContext.getCurrentContext();
HttpServletRequest request = context.getRequest();
StringBuffer originalURL = request.getRequestURL(); // Returns original url
// ...modifying the requestURL
StringBuffer newURL = request.getRequestURL(); // Returns new url

Solution

  • The comment from Jozef seems to be correct: it does not appear to be possible to modify the request URL in this way. This documentation https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html also doesn't show any methods that would seem to allow it either.