Class AbstractHTTPEngine

java.lang.Object
org.omegazero.proxy.http.AbstractHTTPEngine
All Implemented Interfaces:
org.omegazero.http.util.HTTPResponder, HTTPEngine, HTTPEngineResponderMixin

public abstract class AbstractHTTPEngine extends Object implements HTTPEngine, HTTPEngineResponderMixin
A HTTPEngine with common method implementations.

This implementation uses a single HTTPServer passed in the constructor as the client request processor and any amount of HTTPClients to send requests to UpstreamServers using an appropriate procotol.

HTTPServer and HTTPClient implementations used for this AbstractHTTPEngine need not be thread-safe.

Since:
3.10.1
See Also:
  • Field Details

    • ATTACHMENT_KEY_UPSTREAM_SERVER

      public static final String ATTACHMENT_KEY_UPSTREAM_SERVER
      See Also:
    • ATTACHMENT_KEY_USERVER_CLIENT

      public static final String ATTACHMENT_KEY_USERVER_CLIENT
      See Also:
    • ATTACHMENT_KEY_RESPONSE_TIMEOUT

      public static final String ATTACHMENT_KEY_RESPONSE_TIMEOUT
      See Also:
    • CONNDBG

      protected static final String CONNDBG
      See Also:
    • downstreamConnection

      protected final org.omegazero.net.socket.SocketConnection downstreamConnection
    • proxy

      protected final Proxy proxy
    • config

      protected final HTTPEngineConfig config
    • httpServer

      protected final org.omegazero.http.util.HTTPServer httpServer
    • downstreamConnectionDbgstr

      protected final String downstreamConnectionDbgstr
    • disablePromiseRequestLog

      protected final boolean disablePromiseRequestLog
    • duplexClose

      protected final boolean duplexClose
    • downstreamClosed

      protected boolean downstreamClosed
    • upstreamClients

      protected final Map<UpstreamServer,org.omegazero.proxy.http.AbstractHTTPEngine.HTTPClientSet> upstreamClients
    • switchedProtocolUpstreamConnection

      protected org.omegazero.net.socket.SocketConnection switchedProtocolUpstreamConnection
  • Constructor Details

    • AbstractHTTPEngine

      public AbstractHTTPEngine(org.omegazero.net.socket.SocketConnection downstreamConnection, Proxy proxy, HTTPEngineConfig config, org.omegazero.http.util.HTTPServer httpServer)
      Creates a new AbstractHTTPEngine.
      Parameters:
      downstreamConnection - The client connection
      proxy - The Proxy instance
      httpServer - The HTTPServer implementation to use
  • Method Details

    • getHTTPVersionName

      public abstract String getHTTPVersionName()
      Returns the HTTP version name string used for the HTTPMessage version field.

      This string is also used as the protocol name of this implementation.

      Specified by:
      getHTTPVersionName in interface HTTPEngineResponderMixin
      Returns:
      The HTTP version name
    • isDownstreamConnectionSecure

      public abstract boolean isDownstreamConnectionSecure()
      Returns true if the downstream (client) connection is encrypted.
      Returns:
      if encrypted
    • getRequestLogger

      public abstract org.omegazero.common.logging.Logger getRequestLogger()
      Returns the Logger requests should be logged with.
      Returns:
      The Logger
    • processData

      public void processData(byte[] data)
      Description copied from interface: HTTPEngine
      Processes the given data received over the connection from the client.
      Specified by:
      processData in interface HTTPEngine
      Parameters:
      data - Incoming data of a client to process
    • close

      public void close()
      Description copied from interface: HTTPEngine
      Called when the connection to the client closes.
      Specified by:
      close in interface HTTPEngine
    • getDownstreamConnection

      public org.omegazero.net.socket.SocketConnection getDownstreamConnection()
      Description copied from interface: HTTPEngine
      Returns the SocketConnection to the client associated with this instance.
      Specified by:
      getDownstreamConnection in interface HTTPEngine
      Specified by:
      getDownstreamConnection in interface HTTPEngineResponderMixin
      Returns:
      The SocketConnection to the client
    • respond

      public void respond(org.omegazero.http.common.HTTPRequest request, org.omegazero.http.common.HTTPResponseData responsedata)
      Specified by:
      respond in interface HTTPEngineResponderMixin
      Specified by:
      respond in interface org.omegazero.http.util.HTTPResponder
    • respond

      public void respond(org.omegazero.http.common.HTTPRequest request, int status, byte[] data, String... headers)
      Specified by:
      respond in interface org.omegazero.http.util.HTTPResponder
    • respondError

      public void respondError(org.omegazero.http.common.HTTPRequest request, int status, String title, String message, String... headers)
      Description copied from interface: HTTPEngine
      Selects an appropriate HTTPErrdoc template and generates a response body using it.

      The resulting body is sent as a HTTP response with the given status and headers.

      Specified by:
      respondError in interface HTTPEngine
      Parameters:
      request - The request to respond to
      status - The status code of the response
      title - Title of the error message
      message - Error message
      headers - Headers to send in the response. See
      invalid reference
      #respond(HTTPMessage, int, byte[], String...)
      for more information
      See Also:
    • respondUNetError

      protected void respondUNetError(org.omegazero.http.common.HTTPRequest request, int status, String message, org.omegazero.net.socket.SocketConnection uconn, UpstreamServer userver)
    • respondInternalError

      protected void respondInternalError(org.omegazero.http.common.HTTPRequest request, Throwable e)
    • logUNetError

      protected static void logUNetError(Object... o)