Interface HTTPHandler

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface HTTPHandler
Handles an HTTP request from a client.
Author:
Brian Pontarelli
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    handle(HTTPRequest request, HTTPResponse response)
    Handles the processing of a request and filling out the response.
  • Method Details

    • handle

      void handle(HTTPRequest request, HTTPResponse response) throws Exception
      Handles the processing of a request and filling out the response. If this method returns normally, it is assumed that the HTTP response is complete and the headers match the body (or lack thereof) so that the client can process the response properly.

      If the handler wishes to close the connection, it should either include the header Connection: close or throw an exception. If an exception is thrown, the HTTPServer will determine if the response is malformed (i.e. truncated), in which case the connection will be closed automatically, or if the response can be changed to a 500 response.

      Parameters:
      request - The request from the client.
      response - The response sent back to the client.
      Throws:
      Exception - If the processing failed and the response should be truncated or replaced. The connection will always be closed.