RequestFilter doing redirects, does it skip page render?


#1

If you set a redirect URL in the response object returned from a RequestFilter, will the rest of the page render be skipped or will it still attempt to render the page before sending the redirect header back to the browser?


#2

I guess you mean ResponseFilter? We don’t support RequestFilter yet, as far as I know.

If you set the "redirect" property on the response, it is the same as setting a “Location” header in the response and HTTP status 303. This will not change whatever body was set on the response before.

So page rendering happens before ResponseFilter, and the body rendered will be sent in the response if the response filter is not changing it.
However if the status is a redirect code 3xx, the browser will ignore anything that comes in the body and just redirect to a new URL.


#3

Ah, I am so used to RequestFilters that I was expecting this to also be a request filter, haha.

Ok, I will probably have to implement my own RequestFilter in Java then, since I don’t want to spend time to attempt to render the page, if there is a redirect. Thanks for clearing that up :slight_smile:


#4

NB! If you do this redirect directly in a page controller, the overhead should not be very big, but I guess you want to handle this more generally? We are working on support for requestFilters btw.


#5

Yeah, I am creating an admin / management interface for specifying “from / to” URL pairs and want to be able to hook into any request coming in, more or less. Also aiming to keep track of when the redirect was executed last, so we clean up redirects that are no longer needed, and can avoid ending up with 3500+ redirects in Apache like we have in the system we are replacing :stuck_out_tongue:

Very nice to hear that you are working on making request filters available in the javascript part of XP as well.


#6