Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Modifying HTTP response content with a servlet filter

The response wrapper approach is historically how such transformations were done.  However it is a lot of boilerplate code, very easy to get wrong and fails completely if the async IO API is used.

So another approach to consider is to use the jetty API for interceptors (see GzipHandler for an example) that will work with any content source.   Ultimately I'd like to propose a standards based approach for this in Servlet-5.x, but it will be a while before such new features can be considered because of the distraction of renaming everything to jakarta.servlet.*

cheers








On Tue, 18 Feb 2020 at 12:55, Peter Boughton <jetty@xxxxxxxxxxxxxxxxx> wrote:
Hi,

I need to modify the content of responses, so I'm writing a filter.

I found a couple of different approaches here:
https://stackoverflow.com/questions/14736328/looking-for-an-example-for-inserting-content-into-the-response-using-a-servlet-f#14736818

The simpler solution from iTech works - but only when directly
requesting a file.

i.e. example.com/dir/index.html works, but example.com/dir/ returns the
unmodified content of index.html

The longer (accepted) solution works in both cases, so I'm guessing its
convoluted use of getOutputStream/etc is somehow relevant to it working,
but I don't see why the same file triggers different behaviour, just
because it's going via the default/welcome file mechanism.

Is it really necessary to jump through all those hoops in order to get
and set response content, or am I missing some simpler way?


Thanks,

Peter

_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users


--

Back to the top