java.lang.Object
org.miaixz.bus.http.metric.http.Http2Writer
- All Implemented Interfaces:
Closeable,AutoCloseable
Writes HTTP/2 transport frames.
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Method Summary
Modifier and TypeMethodDescriptionvoidapplyAndAckSettings(Http2Settings peerSettings) AppliespeerSettingsand then sends a settings ACK.voidclose()voidWrites the HTTP/2 connection preface.voiddata(boolean outFinished, int streamId, org.miaixz.bus.core.io.buffer.Buffer source, int byteCount) Sends a DATA frame.voidflush()Flushes all buffered data on the underlying sink.voidframeHeader(int streamId, int length, byte type, byte flags) Writes an HTTP/2 frame header.voidgoAway(int lastGoodStreamId, Http2ErrorCode errorCode, byte[] debugData) Informs the peer to stop creating streams.voidheaders(boolean outFinished, int streamId, List<Http2Header> headerBlock) Writes a HEADERS frame, followed by any necessary CONTINUATION frames.intReturns the maximum size of bytes that may be sent in a single call todata(boolean, int, org.miaixz.bus.core.io.buffer.Buffer, int).voidping(boolean ack, int payload1, int payload2) Sends a connection-level ping to the peer.voidpushPromise(int streamId, int promisedStreamId, List<Http2Header> requestHeaders) HTTP/2 only.voidrstStream(int streamId, Http2ErrorCode errorCode) Sends a RST_STREAM frame to terminate a stream.voidsettings(Http2Settings settings) Writes HTTP/2 settings to the peer.voidwindowUpdate(int streamId, long windowSizeIncrement) Inform peer that an additionalwindowSizeIncrementbytes can be sent onstreamId, or on the connection ifstreamIdis zero.
-
Method Details
-
connectionPreface
Writes the HTTP/2 connection preface. This must be sent by the client at the beginning of a connection.- Throws:
IOException- if an I/O error occurs.
-
applyAndAckSettings
AppliespeerSettingsand then sends a settings ACK.- Parameters:
peerSettings- The settings received from the peer.- Throws:
IOException- if an I/O error occurs.
-
pushPromise
public void pushPromise(int streamId, int promisedStreamId, List<Http2Header> requestHeaders) throws IOException HTTP/2 only. Sends push promise headers. A push promise contains all the headers associated with a server-initiated request, and apromisedStreamIdthat will be used for the response frames. The push promise frame is sent as part of the response tostreamId. The priority ofpromisedStreamIdis one greater than that ofstreamId.- Parameters:
streamId- The client-initiated stream ID. Must be an odd number.promisedStreamId- The server-initiated stream ID. Must be an even number.requestHeaders- Minimally includes:method,:scheme,:authority, and:path.- Throws:
IOException- if an I/O error occurs.
-
flush
Flushes all buffered data on the underlying sink.- Throws:
IOException- if an I/O error occurs.
-
rstStream
Sends a RST_STREAM frame to terminate a stream.- Parameters:
streamId- The stream ID.errorCode- The error code indicating the reason for termination.- Throws:
IOException- if an I/O error occurs.
-
maxDataLength
public int maxDataLength()Returns the maximum size of bytes that may be sent in a single call todata(boolean, int, org.miaixz.bus.core.io.buffer.Buffer, int).- Returns:
- The maximum data length.
-
data
public void data(boolean outFinished, int streamId, org.miaixz.bus.core.io.buffer.Buffer source, int byteCount) throws IOException Sends a DATA frame.- Parameters:
outFinished- True if this is the last frame to be sent on this stream.streamId- The stream ID.source- The buffer to draw bytes from. May be null if byteCount is 0.byteCount- Must be between 0 and the minimum ofsource.lengthandmaxDataLength().- Throws:
IOException- if an I/O error occurs.
-
settings
Writes HTTP/2 settings to the peer.- Parameters:
settings- The settings to send.- Throws:
IOException- if an I/O error occurs.
-
ping
Sends a connection-level ping to the peer.ackindicates this is a reply. The data inpayload1andpayload2is opaque binary, and there are no rules on the content.- Parameters:
ack- True if this is a reply to a ping from the peer.payload1- The first payload integer.payload2- The second payload integer.- Throws:
IOException- if an I/O error occurs.
-
goAway
public void goAway(int lastGoodStreamId, Http2ErrorCode errorCode, byte[] debugData) throws IOException Informs the peer to stop creating streams. We last processedlastGoodStreamId, or zero if no streams were processed.- Parameters:
lastGoodStreamId- The last stream ID that was processed, or zero if no streams were processed.errorCode- The reason for closing the connection.debugData- Opaque debug data for HTTP/2 only.- Throws:
IOException- if an I/O error occurs.
-
windowUpdate
Inform peer that an additionalwindowSizeIncrementbytes can be sent onstreamId, or on the connection ifstreamIdis zero.- Parameters:
streamId- The stream ID.windowSizeIncrement- The number of bytes to increment the window by.- Throws:
IOException- if an I/O error occurs.
-
frameHeader
Writes an HTTP/2 frame header.- Parameters:
streamId- The stream ID.length- The length of the frame payload.type- The frame type.flags- The frame flags.- Throws:
IOException- if an I/O error occurs.
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
headers
public void headers(boolean outFinished, int streamId, List<Http2Header> headerBlock) throws IOException Writes a HEADERS frame, followed by any necessary CONTINUATION frames.- Parameters:
outFinished- True if this is the last frame to be sent on this stream.streamId- The stream ID.headerBlock- The list of headers to write.- Throws:
IOException- if an I/O error occurs.
-