Interface HTTPServer

All Superinterfaces:
AutoCloseable, Closeable, HTTPResponder

public interface HTTPServer extends HTTPResponder, Closeable
A HTTPServer is associated with a single client connection from which it receives data, which is then processed to create HTTPServerStreams usable by the application.
Since:
1.4.1
  • Field Summary

    Fields inherited from interface org.omegazero.http.util.HTTPResponder

    EMPTY_BYTE_ARRAY
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Terminates this HTTPServer at any time, causing no further callbacks to be called and the connection to be terminated.
    Returns a (possibly unmodifiable) collection of all currently active request transactions managed by this HTTPServer.
    Returns the client connection this HTTPServer is associated with.
    default boolean
    Returns true if server push is supported and enabled.
    void
    Sets the callback that is called when a new HTTPServerStream was created after receiving a request from the client.
    void
    receive(byte[] data)
    Called by the application when it receives data from the client connection this HTTPServer is associated with.

    Methods inherited from interface org.omegazero.http.util.HTTPResponder

    respond, respond
  • Method Details

    • receive

      void receive(byte[] data)
      Called by the application when it receives data from the client connection this HTTPServer is associated with.

      Any protocol errors caused by malformed data passed to this method should be handled internally (for example, simply closing the connection is an appropriate minimum action).

      Parameters:
      data - The data
    • getConnection

      WritableSocket getConnection()
      Returns the client connection this HTTPServer is associated with.
      Returns:
      The connection
    • close

      void close()
      Terminates this HTTPServer at any time, causing no further callbacks to be called and the connection to be terminated.

      Calling this method also closes all active requests.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • isServerPushEnabled

      default boolean isServerPushEnabled()
      Returns true if server push is supported and enabled.
      Returns:
      true if server push is available
    • onNewRequest

      void onNewRequest(Consumer<HTTPServerStream> callback)
      Sets the callback that is called when a new HTTPServerStream was created after receiving a request from the client.

      No callbacks in the HTTPServerStream are called before the given callback has returned.

      Parameters:
      callback - The callback
      Implementation Note:
      The implementation should catch exceptions thrown by the callback and return a HTTP 500 error
    • getActiveRequests

      Collection<HTTPServerStream> getActiveRequests()
      Returns a (possibly unmodifiable) collection of all currently active request transactions managed by this HTTPServer. This is the set of all HTTPServerStreams which have not received a complete response yet.
      Returns:
      The collection of active HTTPServerStreams