[undertow-dev] Force a HttpHandler to accept POST only
Stuart Douglas
sdouglas at redhat.com
Mon Dec 9 08:44:27 EST 2013
>
> On 9 décembre 2013 at 11:10:49, Stuart Douglas (sdouglas at redhat.com) wrote:
> What do you want to happen if it is not a post request?
>
> I was thinking about a 404 error, but indeed, 405 is more relevant.
>
> The simplest way is just:
>
> if(!exchange.getRequestMethod().equals(Methods.POST)) {
> exchange.setResponseCode(405);
> exchange.endExchange();
> return;
> }
> This way suits me, thank you.
>
> How can I retrieve the POST parameters ? I only can access the GET ones with
> getQueryParameters().
For now you need to use io.undertow.server.handlers.form.FormDataParser (see io.undertow.server.handlers.form.FormDataParserTestCase for an example).
I am not super happy with this API so it will probably change soon.
>
> If you want to pick a handler to invoke based on the method you can use:
>
> Handlers.predicate(Predicates.method(Methods.POST), postHandler,
> nonPostHandler);
> Do you think it’s a good idea to create a handler for any 404 error page and
> use it here ?
>
> If so, is it possible to set it as the default handler for all 404 errors ?
> (I can do the check manually but I’m wondering if it is supported by
> default)
io.undertow.server.handlers.ResponseCodeHandler#HANDLE_404
This is a handler that sets a 404 response code and ends.
If you want to generate a default error page for 404 responses have a look at io.undertow.server.handlers.error.SimpleErrorPageHandler for an example of how to do this.
Stuart
>
>
>
> Stuart
>
> ----- Original Message -----
> > From: "Samy Dindane" <samy at dindane.com>
> > To: undertow-dev at lists.jboss.org
> > Sent: Sunday, 8 December, 2013 6:09:23 PM
> > Subject: [undertow-dev] Force a HttpHandler to accept POST only
> >
> > Hi folks,
> >
> > I have a HttpHandler that I want to reach with POST requests only .
> > I tried exchange.setRequestMethod(new HttpString("POST”)) inside
> > handleRequest() , but the HttpHandler still responds to GET requests.
> >
> > Is there any way to do this?
> >
> > In case you’d like to check out the code, it can be found here .
> > Thank you.
> >
> > Samy
> >
> > _______________________________________________
> > undertow-dev mailing list
> > undertow-dev at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/undertow-dev
>
More information about the undertow-dev
mailing list