public interface MuHandler
An HTTP request handler. This can be used to inspect HTTP requests and return responses, or act as a filter that intercepts requests before going to subsequent handlers (for logging, adding common response headers, or security filtering etc).
Handlers are executed in the order they are registered with Mu-Server. By returning true
from a
handler you are indicating that the handler processing should stop; false
means to go to the next
handler.
This type of handler allows you to look at the request path and decide whether to take action or not. Note
that if you want a handler for a specific URL you may consider using MuServerBuilder.addHandler(io.muserver.Method, java.lang.String, io.muserver.RouteHandler)
instead.
Modifier and Type | Method and Description |
---|---|
boolean |
handle(MuRequest request,
MuResponse response)
Called when an HTTP request is made (unless a previous handler stopped handler processing)
|
boolean handle(MuRequest request, MuResponse response) throws Exception
request
- The HTTP request.response
- The HTTP response.false
to continue processing the next handler (for example if writing a filter or inspector); or true
to stop processing (normally done if this handler sent a response).Exception
- Any uncaught exceptions will result in a 500 error code being returned to the client with a simple message.Copyright © 2017–2019. All rights reserved.