Package org.omegazero.http.h2
Class HTTP2Client
java.lang.Object
org.omegazero.http.h2.HTTP2Endpoint
org.omegazero.http.h2.HTTP2Client
An instance of this class represents a HTTP/2 client, a special type of
HTTP2Endpoint.- Since:
- 1.2.1
-
Field Summary
Fields inherited from class org.omegazero.http.h2.HTTP2Endpoint
closeWaitStreams, closeWaitTimeout, connection, highestStreamId, hpack, peerInitiatedStreams, settings, streams -
Constructor Summary
ConstructorsConstructorDescriptionHTTP2Client(WritableSocket connection, HTTP2Settings settings, HPackContext hpack) Creates a newHTTP2Clientinstance.HTTP2Client(WritableSocket connection, HTTP2Settings settings, HPackContext.Session hpackSession, boolean useHuffmanEncoding) Creates a newHTTP2Clientinstance. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this client.Creates a newMessageStreamto send a request with.handlePushPromise(HTTPRequest promisedRequest) Creates a newMessageStreamthat expects to receive a promise response by the server.protected HTTP2StreamnewStreamForFrame(int streamId, int type, int flags, byte[] payload) Processes a frame received on a previously nonexistent stream and creates a newHTTP2Streamfor it, if appropriate.voidonMessageStreamClosed(MessageStream messageStream) This method must be called by the application after a message stream returned bycreateRequestStream()orhandlePushPromise(HTTPRequest)closed to remove it from internal storage.protected voidonSettingsUpdate(HTTP2Settings settings) This method is called when a SETTINGS frame is received from the server.voidstart()Starts the HTTP/2 client by sending the client connection preface and SETTINGS frame.Methods inherited from class org.omegazero.http.h2.HTTP2Endpoint
checkLocalCreateStream, checkRemoteCreateStream, getConnection, getControlStream, getOpenLocallyInitiatedMessageStreamCount, getOpenMessageStreamCount, getOpenPeerInitiatedMessageStreamCount, getStream, getStreams, handleConnectionWindowUpdate, processData, processData0, registerStream, registerStream, streamClosed
-
Constructor Details
-
HTTP2Client
public HTTP2Client(WritableSocket connection, HTTP2Settings settings, HPackContext.Session hpackSession, boolean useHuffmanEncoding) Creates a newHTTP2Clientinstance.- Parameters:
connection- The underlying connectionsettings- The local settingshpackSession- The HPACK session to useuseHuffmanEncoding- Whether to enable HPACK Huffman Coding
-
HTTP2Client
Creates a newHTTP2Clientinstance.- Parameters:
connection- The underlying connectionsettings- The local settingshpack- TheHPackContextto use
-
-
Method Details
-
start
public void start()Starts the HTTP/2 client by sending the client connection preface and SETTINGS frame. -
createRequestStream
Creates a newMessageStreamto send a request with. The caller will need to callMessageStream.sendHTTPMessage(org.omegazero.http.common.HTTPMessage, boolean)on the returned stream to start the message exchange.- Returns:
- The created
MessageStream, ornullif noMessageStreamcould be created - See Also:
-
handlePushPromise
Creates a newMessageStreamthat expects to receive a promise response by the server.The stream ID of the
HTTPRequestis the promised stream ID by the server and must be an even number.Usable in the
onPushPromisecallback of aMessageStream.- Parameters:
promisedRequest- The promise request sent by the server- Returns:
- The created
MessageStream - Throws:
IllegalArgumentException- If the given request is not a valid pushed requestHTTP2ConnectionError- If MAX_CONCURRENT_STREAMS is exceeded- See Also:
-
onMessageStreamClosed
This method must be called by the application after a message stream returned bycreateRequestStream()orhandlePushPromise(HTTPRequest)closed to remove it from internal storage. CallsHTTP2Endpoint.streamClosed(MessageStream).- Parameters:
messageStream- The closed message stream- Throws:
IllegalStateException- If the stream is not closed
-
close
public void close()Closes this client. Prior to closing the underlying connection, all active message streams are canceled and a GOAWAY frame is sent with no error.- Throws:
IOException- If an IO error occurs
-
onSettingsUpdate
This method is called when a SETTINGS frame is received from the server.- Parameters:
settings- The new remote settings
-
newStreamForFrame
Description copied from class:HTTP2EndpointProcesses a frame received on a previously nonexistent stream and creates a newHTTP2Streamfor it, if appropriate.The returned stream is registered automatically using
HTTP2Endpoint.registerStream(HTTP2Stream, boolean). Ifnullis returned (no stream was created), and the frame type is not PRIORITY, it will be treated as a connection error of type PROTOCOL_ERROR.When creating a stream, the implementation should call
HTTP2Endpoint.checkRemoteCreateStream()first.- Specified by:
newStreamForFramein classHTTP2Endpoint- Parameters:
streamId- The stream ID of the new streamtype- The frame typeflags- The frame flagspayload- The frame payload- Returns:
- The new stream, or
nullif no stream is appropriate
-