Package org.omegazero.proxy.http
Class HTTPCommon
java.lang.Object
org.omegazero.proxy.http.HTTPCommon
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final intstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final longstatic final intstatic final boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringGenerates a date string formatted for use in the Date HTTP header.static StringGenerates an appropriate error message string from the givenThrowablethat occurred on an upstream connection.static StringhstrFromInetAddress(InetAddress address) 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 (returnsinvalid reference
#hasResponseBody(HTTPMessage, HTTPMessage)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 deletedstatic StringrequestId(org.omegazero.net.socket.SocketConnection connection) Generates a pseudo-random request ID from the given parameters and system properties.static voidsetDefaultHeaders(Proxy proxy, org.omegazero.http.common.HTTPMessage msg) Sets several common HTTP headers.static booleansetRequestResponse(org.omegazero.http.common.HTTPRequest request, org.omegazero.http.common.HTTPResponse response) Sets the response of the given request to response atomically and returnstrueif successful orfalseif the given request already has a response associated with it.static StringshortenRequestId(String full) Shortens a request ID generated byrequestId(SocketConnection)to 8 characters, used in log outputs.
-
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
-
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
- See Also:
-
MSG_BAD_REQUEST
- See Also:
-
MSG_NO_SERVER
- See Also:
-
MSG_REQUEST_TIMEOUT
- See Also:
-
MSG_SERVER_ERROR
- See Also:
-
MSG_UPSTREAM_CONNECT_FAILED
- See Also:
-
MSG_UPSTREAM_CONNECT_TIMEOUT
- See Also:
-
MSG_UPSTREAM_RESPONSE_TIMEOUT
- See Also:
-
MSG_UPSTREAM_RESPONSE_INVALID
- See Also:
-
MSG_UPSTREAM_CONNECTION_ERROR
- See Also:
-
MSG_UPSTREAM_CONNECTION_CLOSED
- See Also:
-
MSG_PROTO_NOT_SUPPORTED
- See Also:
-
-
Constructor Details
-
HTTPCommon
public HTTPCommon()
-
-
Method Details
-
dateString
Generates a date string formatted for use in the Date HTTP header.- Returns:
- The date string
-
hstrFromInetAddress
-
requestId
Generates a pseudo-random request ID from the given parameters and system properties.- Parameters:
connection- The remote connection- Returns:
- The request ID
-
shortenRequestId
Shortens a request ID generated byrequestId(SocketConnection)to 8 characters, used in log outputs.- Parameters:
full- The full request ID- Returns:
- The shortened request ID
-
setDefaultHeaders
Sets several common HTTP headers.- Parameters:
proxy- The proxy instancemsg- The HTTP message to add headers to
-
getUpstreamErrorMessage
Generates an appropriate error message string from the givenThrowablethat 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 returnstrueif successful orfalseif the given request already has a response associated with it.- Parameters:
request- The requestresponse- The response- Returns:
trueif successful,falseif 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 (
returns
invalid reference
#hasResponseBody(HTTPMessage, HTTPMessage)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 benullresponse- The responsedata- 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
-