Package io.github.mahmoudimus.http3
Class Http3FrameWriter
java.lang.Object
io.github.mahmoudimus.http3.Http3FrameWriter
Writes HTTP/3 frames to one QUIC stream. Each call builds its frame in memory and hands it to the
stream in one
write. A QUIC stream has a single writer, so there is no locking; if
several threads share one stream, they must serialize their calls. Nothing is flushed until
flush().
Arguments that would produce a frame the protocol forbids (an HTTP/2-only setting, say) are
rejected with IllegalArgumentException before anything is written. The static
encode(Http3Frame) methods give the bytes of a frame without a stream.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]encode(Http3Frame frame) The bytes of one frame.static voidencode(Http3Frame frame, ByteBuffer buf) Puts the bytes of one frame at the buffer's position.voidflush()Flushes the stream.voidwriteCancelPush(long pushId) A CANCEL_PUSH frame.voidwriteData(byte[] data) One DATA frame with all ofdata.voidwriteData(byte[] data, int offset, int length) One DATA frame.voidwriteFrame(Http3Frame frame) Writes one frame exactly as given.voidwriteGoAway(long id) A GOAWAY frame.voidwriteHeaders(byte[] fieldSection) A HEADERS frame carrying an encoded field section fromQpackEncoder.voidwriteMaxPushId(long pushId) A MAX_PUSH_ID frame.voidwritePushPromise(long pushId, byte[] fieldSection) A PUSH_PROMISE frame.voidwriteSettings(Http3Settings settings) A SETTINGS frame.voidwriteStreamType(long streamType) Writes the stream type that must start a unidirectional stream; seeHttp3StreamType.
-
Constructor Details
-
Http3FrameWriter
A writer for one stream.- Parameters:
out- the stream's bytes; give it a buffered stream and flush it as needed
-
-
Method Details
-
writeStreamType
Writes the stream type that must start a unidirectional stream; seeHttp3StreamType.- Parameters:
streamType- the stream type- Throws:
IOException- if writing fails
-
writeFrame
Writes one frame exactly as given.- Parameters:
frame- the frame- Throws:
IOException- if writing fails
-
writeData
One DATA frame.- Parameters:
data- the contentoffset- where it starts indatalength- how many bytes- Throws:
IOException- if writing fails
-
writeData
One DATA frame with all ofdata.- Parameters:
data- the content- Throws:
IOException- if writing fails
-
writeHeaders
A HEADERS frame carrying an encoded field section fromQpackEncoder.- Parameters:
fieldSection- the encoded field section- Throws:
IOException- if writing fails
-
writeSettings
A SETTINGS frame.- Parameters:
settings- the settings- Throws:
IOException- if writing fails
-
writePushPromise
A PUSH_PROMISE frame.- Parameters:
pushId- the push it promisesfieldSection- the encoded field section of the promised request- Throws:
IOException- if writing fails
-
writeCancelPush
A CANCEL_PUSH frame.- Parameters:
pushId- the push to cancel- Throws:
IOException- if writing fails
-
writeGoAway
A GOAWAY frame.- Parameters:
id- the stream or push id- Throws:
IOException- if writing fails
-
writeMaxPushId
A MAX_PUSH_ID frame.- Parameters:
pushId- the largest push id the server may use- Throws:
IOException- if writing fails
-
flush
Flushes the stream.- Throws:
IOException- if flushing fails
-
encode
The bytes of one frame.- Parameters:
frame- the frame- Returns:
- its type, length and payload
-
encode
Puts the bytes of one frame at the buffer's position.- Parameters:
frame- the framebuf- where to put it- Throws:
BufferOverflowException- if it does not fit; nothing is written then
-