Class HTTPCommon

java.lang.Object
org.omegazero.proxy.http.HTTPCommon

public final class HTTPCommon extends Object
  • Field Details

    • IADDR_HASH_SALT

      public static final int IADDR_HASH_SALT
    • USOCKET_ERROR_DEBUG

      public static final boolean USOCKET_ERROR_DEBUG
    • REQUEST_ID_SEPARATOR

      public static final String REQUEST_ID_SEPARATOR
    • REQUEST_ID_TIME_LENGTH

      public static final int REQUEST_ID_TIME_LENGTH
    • REQUEST_ID_TIME_BASE

      public static final long REQUEST_ID_TIME_BASE
    • ATTACHMENT_KEY_REQUEST_ID

      public static final String ATTACHMENT_KEY_REQUEST_ID
      See Also:
    • MSG_BAD_REQUEST

      public static final String MSG_BAD_REQUEST
      See Also:
    • MSG_NO_SERVER

      public static final String MSG_NO_SERVER
      See Also:
    • MSG_REQUEST_TIMEOUT

      public static final String MSG_REQUEST_TIMEOUT
      See Also:
    • MSG_SERVER_ERROR

      public static final String MSG_SERVER_ERROR
      See Also:
    • MSG_UPSTREAM_CONNECT_FAILED

      public static final String MSG_UPSTREAM_CONNECT_FAILED
      See Also:
    • MSG_UPSTREAM_CONNECT_TIMEOUT

      public static final String MSG_UPSTREAM_CONNECT_TIMEOUT
      See Also:
    • MSG_UPSTREAM_RESPONSE_TIMEOUT

      public static final String MSG_UPSTREAM_RESPONSE_TIMEOUT
      See Also:
    • MSG_UPSTREAM_RESPONSE_INVALID

      public static final String MSG_UPSTREAM_RESPONSE_INVALID
      See Also:
    • MSG_UPSTREAM_CONNECTION_ERROR

      public static final String MSG_UPSTREAM_CONNECTION_ERROR
      See Also:
    • MSG_UPSTREAM_CONNECTION_CLOSED

      public static final String MSG_UPSTREAM_CONNECTION_CLOSED
      See Also:
    • MSG_PROTO_NOT_SUPPORTED

      public static final String MSG_PROTO_NOT_SUPPORTED
      See Also:
  • Constructor Details

    • HTTPCommon

      public HTTPCommon()
  • Method Details

    • dateString

      public static String dateString()
      Generates a date string formatted for use in the Date HTTP header.
      Returns:
      The date string
    • hstrFromInetAddress

      public static String hstrFromInetAddress(InetAddress address)
    • requestId

      public static String requestId(org.omegazero.net.socket.SocketConnection connection)
      Generates a pseudo-random request ID from the given parameters and system properties.
      Parameters:
      connection - The remote connection
      Returns:
      The request ID
    • shortenRequestId

      public static String shortenRequestId(String full)
      Shortens a request ID generated by requestId(SocketConnection) to 8 characters, used in log outputs.
      Parameters:
      full - The full request ID
      Returns:
      The shortened request ID
    • setDefaultHeaders

      public static void setDefaultHeaders(Proxy proxy, org.omegazero.http.common.HTTPMessage msg)
      Sets several common HTTP headers.
      Parameters:
      proxy - The proxy instance
      msg - The HTTP message to add headers to
    • getUpstreamErrorMessage

      public static String getUpstreamErrorMessage(Throwable e)
      Generates an appropriate error message string from the given Throwable that occurred on an upstream connection.
      Parameters:
      e - An error in an upstream connection
      Returns:
      An error message created from the given exception
    • setRequestResponse

      public static boolean setRequestResponse(org.omegazero.http.common.HTTPRequest request, org.omegazero.http.common.HTTPResponse response)
      Sets the response of the given request to response atomically and returns true if successful or false if the given request already has a response associated with it.
      Parameters:
      request - The request
      response - The response
      Returns:
      true if successful, false if the request already had a response
      Since:
      3.3.1
    • prepareHTTPResponse

      public static byte[] prepareHTTPResponse(org.omegazero.http.common.HTTPRequest request, org.omegazero.http.common.HTTPResponse response, byte[] data)
      Prepares the given response by performing one of the following:
      • If the response is a result of a request with the HEAD method, data is set to an empty array and any Content-Length header is deleted
      • If the response should contain a response body (
        invalid reference
        #hasResponseBody(HTTPMessage, HTTPMessage)
        returns true), the Content-Length header is set to the length of data
      • If the response should not contain a response body and data is empty, any Content-Length header is deleted
      Parameters:
      request - The request that caused the response. May be null
      response - The response
      data - Data of the response
      Returns:
      Possibly edited data
      Throws:
      IllegalArgumentException - If the response should not contain a response body, the request is not made with the HEAD method and data is non-empty
      Since:
      3.3.1