Filtering request based on their HTTP method

HTTP offers a mechanism by which a server can reject a request following the method used. For instance you may want to force a page handler to be applied only when a POST request has been made and infom the user-agent of that constraint.

Using the builtin MethodDispatcher

CherryPy 3 comes with a MethodDispatcher which allows your page handlers to be named after the HTTP method they will handle: GET, POST, HEAD, etc. For instance:

Using the builtin default dispatcher

In the previous section we have used a different dispatcher dedicated for handling the HTTP method of the request. However it may happen that you cannot use that dispatcher and would rather keep the default one. In that case you can use a tool such as: