AsyncContext within a Filter is not brittle.
We have a DoSFilter that uses it just fine.
I wasn't clear enough, before committing obviously.
Unfortunately, there's no servlet mechanism to hook into the "about to go committed" event.
My solution, which may fail in certain edge cases, was to wrap the response and set the cookie when `setStatus` is called, which generally only happens when result is about to be committed. This works fine (for now), but obviously is also a little brittle, as it relies on assumptions that doesn't always hold.
Cookies are special and will be applied regardless of the dispatch (normal, async, error, include, forward, etc).
They will never be cleared / rewritten by servlet container behaviors once set.
Why do you want to wait till the end of the request to set it?
Why not set the Cookie before you execute the filter chain?
The content is dependent on what happens in multiple steps in the servlet(s), as I explained in my response to Simon.
While the HTTP spec has a concept of Trailers, which would allow for setting Cookies after the request, using Trailers from within the Servlet spec isn't easy.
And not all HTTP clients (some browsers included) support Trailers.
Right, isn't that the problem with getting gRPC to work natively in browsers?
I did try that, but it failed:
java.lang.IllegalStateException: s=HANDLING rs=BLOCKING os=OPEN is=READY awp=false se=false i=true al=0
at org.eclipse.jetty.server.Request.getAsyncContext(Request.java:592)
I didn’t pursue this much further, because it seemed to be fundamentally brittle.
Also, isn’t the response fully committed when AsyncContext.complete()
is called, i.e. it’s too late to set headers, such as cookies?
Hi,
On Mon, Nov 11, 2019 at 5:25 PM Nils Kilden-Pedersen <nilskp@xxxxxxxxx> wrote:
>
> I can't seem to find much information on how to code async filters.
>
> Basically, how do I know when the filter chain has completed? I need to set a cookie, but only at the very end of the request.
You use Servlet's AsyncListener and implement onComplete().
--
Simone Bordet
----
http://cometd.org
http://webtide.com
Developer advice, training, services and support
from the Jetty & CometD experts.
_______________________________________________
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
_______________________________________________
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
_______________________________________________
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