java.lang.Object
org.miaixz.bus.http.metric.http.Http2Codec
- All Implemented Interfaces:
HttpCodec
Encodes requests and decodes responses using HTTP/2 frames.
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Field Summary
Fields inherited from interface org.miaixz.bus.http.metric.http.HttpCodec
DISCARD_STREAM_TIMEOUT_MILLIS -
Constructor Summary
ConstructorsConstructorDescriptionHttp2Codec(Httpd client, RealConnection realConnection, NewChain chain, Http2Connection connection) Constructs a new Http2Codec. -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()Cancels the stream.Returns the connection that carries the transport.org.miaixz.bus.core.io.sink.SinkcreateRequestBody(Request request, long contentLength) Creates a sink to write the request body.voidFinishes writing the request.voidFlushes the request to the underlying connection.static List<Http2Header> http2HeadersList(Request request) Converts an HTTP request to a list of HTTP/2 headers.org.miaixz.bus.core.io.source.SourceopenResponseBodySource(Response response) Opens a source to read the response body.static Response.BuilderreadHttp2HeadersList(Headers headerBlock, org.miaixz.bus.core.net.Protocol protocol) Creates aResponse.Builderfrom a list of HTTP/2 headers.readResponseHeaders(boolean expectContinue) Reads the response headers from the stream.longreportedContentLength(Response response) Reports the content length of the response.trailers()Returns the trailers of the response.voidwriteRequestHeaders(Request request) Writes the request headers to the stream.
-
Constructor Details
-
Http2Codec
public Http2Codec(Httpd client, RealConnection realConnection, NewChain chain, Http2Connection connection) Constructs a new Http2Codec.- Parameters:
client- The Httpd client instance.realConnection- The real connection to the server.chain- The interceptor chain.connection- The HTTP/2 connection.
-
-
Method Details
-
http2HeadersList
Converts an HTTP request to a list of HTTP/2 headers.- Parameters:
request- The HTTP request.- Returns:
- A list of HTTP/2 headers.
-
readHttp2HeadersList
public static Response.Builder readHttp2HeadersList(Headers headerBlock, org.miaixz.bus.core.net.Protocol protocol) throws IOException Creates aResponse.Builderfrom a list of HTTP/2 headers.- Parameters:
headerBlock- The block of headers.protocol- The HTTP protocol.- Returns:
- A
Response.Builder. - Throws:
IOException- if an I/O error occurs.
-
connection
Returns the connection that carries the transport.- Specified by:
connectionin interfaceHttpCodec- Returns:
- The real connection.
-
createRequestBody
Creates a sink to write the request body.- Specified by:
createRequestBodyin interfaceHttpCodec- Parameters:
request- The request.contentLength- The length of the content.- Returns:
- A sink for writing the request body.
-
writeRequestHeaders
Writes the request headers to the stream.- Specified by:
writeRequestHeadersin interfaceHttpCodec- Parameters:
request- The request.- Throws:
IOException- if an I/O error occurs.
-
flushRequest
Flushes the request to the underlying connection.- Specified by:
flushRequestin interfaceHttpCodec- Throws:
IOException- if an I/O error occurs.
-
finishRequest
Finishes writing the request.- Specified by:
finishRequestin interfaceHttpCodec- Throws:
IOException- if an I/O error occurs.
-
readResponseHeaders
Reads the response headers from the stream.- Specified by:
readResponseHeadersin interfaceHttpCodec- Parameters:
expectContinue- true if a 100-continue response is expected.- Returns:
- A
Response.Builderwith the response headers. - Throws:
IOException- if an I/O error occurs.
-
reportedContentLength
Reports the content length of the response.- Specified by:
reportedContentLengthin interfaceHttpCodec- Parameters:
response- The response.- Returns:
- The content length.
-
openResponseBodySource
Opens a source to read the response body.- Specified by:
openResponseBodySourcein interfaceHttpCodec- Parameters:
response- The response.- Returns:
- A source for reading the response body.
-
trailers
Returns the trailers of the response.- Specified by:
trailersin interfaceHttpCodec- Returns:
- The response trailers.
- Throws:
IOException- if an I/O error occurs.
-
cancel
public void cancel()Cancels the stream.
-