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 newHTTP2Client
instance.HTTP2Client
(WritableSocket connection, HTTP2Settings settings, HPackContext.Session hpackSession, boolean useHuffmanEncoding) Creates a newHTTP2Client
instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes this client.Creates a newMessageStream
to send a request with.handlePushPromise
(HTTPRequest promisedRequest) Creates a newMessageStream
that expects to receive a promise response by the server.protected HTTP2Stream
newStreamForFrame
(int streamId, int type, int flags, byte[] payload) Processes a frame received on a previously nonexistent stream and creates a newHTTP2Stream
for it, if appropriate.void
onMessageStreamClosed
(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 void
onSettingsUpdate
(HTTP2Settings settings) This method is called when a SETTINGS frame is received from the server.void
start()
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 newHTTP2Client
instance.- Parameters:
connection
- The underlying connectionsettings
- The local settingshpackSession
- The HPACK session to useuseHuffmanEncoding
- Whether to enable HPACK Huffman Coding
-
HTTP2Client
Creates a newHTTP2Client
instance.- Parameters:
connection
- The underlying connectionsettings
- The local settingshpack
- TheHPackContext
to use
-
-
Method Details
-
start
public void start()Starts the HTTP/2 client by sending the client connection preface and SETTINGS frame. -
createRequestStream
Creates a newMessageStream
to 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
, ornull
if noMessageStream
could be created - See Also:
-
handlePushPromise
Creates a newMessageStream
that expects to receive a promise response by the server.The stream ID of the
HTTPRequest
is the promised stream ID by the server and must be an even number.Usable in the
onPushPromise
callback 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:HTTP2Endpoint
Processes a frame received on a previously nonexistent stream and creates a newHTTP2Stream
for it, if appropriate.The returned stream is registered automatically using
HTTP2Endpoint.registerStream(HTTP2Stream, boolean)
. Ifnull
is 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:
newStreamForFrame
in classHTTP2Endpoint
- Parameters:
streamId
- The stream ID of the new streamtype
- The frame typeflags
- The frame flagspayload
- The frame payload- Returns:
- The new stream, or
null
if no stream is appropriate
-