Package org.omegazero.proxy.http
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringprotected final HTTPEngineConfigprotected static final Stringprotected final booleanprotected booleanprotected final org.omegazero.net.socket.SocketConnectionprotected final Stringprotected final booleanprotected final org.omegazero.http.util.HTTPServerprotected final Proxyprotected org.omegazero.net.socket.SocketConnectionprotected final Map<UpstreamServer, org.omegazero.proxy.http.AbstractHTTPEngine.HTTPClientSet> Fields inherited from interface org.omegazero.http.util.HTTPResponder
EMPTY_BYTE_ARRAY -
Constructor Summary
ConstructorsConstructorDescriptionAbstractHTTPEngine(org.omegazero.net.socket.SocketConnection downstreamConnection, Proxy proxy, HTTPEngineConfig config, org.omegazero.http.util.HTTPServer httpServer) Creates a newAbstractHTTPEngine. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Called when the connection to the client closes.org.omegazero.net.socket.SocketConnectionReturns theSocketConnectionto the client associated with this instance.abstract StringReturns the HTTP version name string used for theHTTPMessageversionfield.abstract org.omegazero.common.logging.LoggerReturns theLoggerrequests should be logged with.abstract booleanReturnstrueif the downstream (client) connection is encrypted.protected static voidlogUNetError(Object... o) voidprocessData(byte[] data) Processes the given data received over the connection from the client.voidvoidrespond(org.omegazero.http.common.HTTPRequest request, org.omegazero.http.common.HTTPResponseData responsedata) voidrespondError(org.omegazero.http.common.HTTPRequest request, int status, String title, String message, String... headers) Selects an appropriateHTTPErrdoctemplate and generates a response body using it.protected voidrespondInternalError(org.omegazero.http.common.HTTPRequest request, Throwable e) protected voidrespondUNetError(org.omegazero.http.common.HTTPRequest request, int status, String message, org.omegazero.net.socket.SocketConnection uconn, UpstreamServer userver) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.omegazero.proxy.http.HTTPEngine
respondErrorMethods inherited from interface org.omegazero.proxy.util.HTTPEngineResponderMixin
respondError, respondEx, respondUNetError
-
Field Details
-
ATTACHMENT_KEY_UPSTREAM_SERVER
- See Also:
-
ATTACHMENT_KEY_USERVER_CLIENT
- See Also:
-
ATTACHMENT_KEY_RESPONSE_TIMEOUT
- See Also:
-
CONNDBG
- See Also:
-
downstreamConnection
protected final org.omegazero.net.socket.SocketConnection downstreamConnection -
proxy
-
config
-
httpServer
protected final org.omegazero.http.util.HTTPServer httpServer -
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 newAbstractHTTPEngine.- Parameters:
downstreamConnection- The client connectionproxy- TheProxyinstancehttpServer- TheHTTPServerimplementation to use
-
-
Method Details
-
getHTTPVersionName
Returns the HTTP version name string used for theHTTPMessageversionfield.This string is also used as the protocol name of this implementation.
- Specified by:
getHTTPVersionNamein interfaceHTTPEngineResponderMixin- Returns:
- The HTTP version name
-
isDownstreamConnectionSecure
public abstract boolean isDownstreamConnectionSecure()Returnstrueif the downstream (client) connection is encrypted.- Returns:
- if encrypted
-
getRequestLogger
public abstract org.omegazero.common.logging.Logger getRequestLogger()Returns theLoggerrequests should be logged with.- Returns:
- The
Logger
-
processData
public void processData(byte[] data) Description copied from interface:HTTPEngineProcesses the given data received over the connection from the client.- Specified by:
processDatain interfaceHTTPEngine- Parameters:
data- Incoming data of a client to process
-
close
public void close()Description copied from interface:HTTPEngineCalled when the connection to the client closes.- Specified by:
closein interfaceHTTPEngine
-
getDownstreamConnection
public org.omegazero.net.socket.SocketConnection getDownstreamConnection()Description copied from interface:HTTPEngineReturns theSocketConnectionto the client associated with this instance.- Specified by:
getDownstreamConnectionin interfaceHTTPEngine- Specified by:
getDownstreamConnectionin interfaceHTTPEngineResponderMixin- Returns:
- The
SocketConnectionto the client
-
respond
public void respond(org.omegazero.http.common.HTTPRequest request, org.omegazero.http.common.HTTPResponseData responsedata) - Specified by:
respondin interfaceHTTPEngineResponderMixin- Specified by:
respondin interfaceorg.omegazero.http.util.HTTPResponder
-
respond
public void respond(org.omegazero.http.common.HTTPRequest request, int status, byte[] data, String... headers) - Specified by:
respondin interfaceorg.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:HTTPEngineSelects an appropriateHTTPErrdoctemplate and generates a response body using it.The resulting body is sent as a HTTP response with the given status and headers.
- Specified by:
respondErrorin interfaceHTTPEngine- Parameters:
request- The request to respond tostatus- The status code of the responsetitle- Title of the error messagemessage- Error messageheaders- Headers to send in the response. Seefor more informationinvalid reference
#respond(HTTPMessage, int, byte[], String...)- 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
-
logUNetError
-