Package io.muserver

Interface MuHandler

  • All Known Implementing Classes:
    ContextHandler, CORSHandler, HttpsRedirector, ResourceHandler, RestHandler, WebSocketHandler

    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.

    • Method Detail

      • handle

        boolean handle​(MuRequest request,
                       MuResponse response)
                throws java.lang.Exception
        Called when an HTTP request is made (unless a previous handler stopped handler processing)
        request - The HTTP request.
        response - The HTTP response.
        Return 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).
        java.lang.Exception - Any uncaught exceptions will result in a 500 error code being returned to the client with a simple message.