Module bus.http

Class Http2Codec

java.lang.Object
org.miaixz.bus.http.metric.http.Http2Codec
All Implemented Interfaces:
HttpCodec

public class Http2Codec extends Object implements HttpCodec
Encodes requests and decodes responses using HTTP/2 frames.
Since:
Java 17+
Author:
Kimi Liu
  • 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

      public static List<Http2Header> http2HeadersList(Request request)
      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 a Response.Builder from 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

      public RealConnection connection()
      Returns the connection that carries the transport.
      Specified by:
      connection in interface HttpCodec
      Returns:
      The real connection.
    • createRequestBody

      public org.miaixz.bus.core.io.sink.Sink createRequestBody(Request request, long contentLength)
      Creates a sink to write the request body.
      Specified by:
      createRequestBody in interface HttpCodec
      Parameters:
      request - The request.
      contentLength - The length of the content.
      Returns:
      A sink for writing the request body.
    • writeRequestHeaders

      public void writeRequestHeaders(Request request) throws IOException
      Writes the request headers to the stream.
      Specified by:
      writeRequestHeaders in interface HttpCodec
      Parameters:
      request - The request.
      Throws:
      IOException - if an I/O error occurs.
    • flushRequest

      public void flushRequest() throws IOException
      Flushes the request to the underlying connection.
      Specified by:
      flushRequest in interface HttpCodec
      Throws:
      IOException - if an I/O error occurs.
    • finishRequest

      public void finishRequest() throws IOException
      Finishes writing the request.
      Specified by:
      finishRequest in interface HttpCodec
      Throws:
      IOException - if an I/O error occurs.
    • readResponseHeaders

      public Response.Builder readResponseHeaders(boolean expectContinue) throws IOException
      Reads the response headers from the stream.
      Specified by:
      readResponseHeaders in interface HttpCodec
      Parameters:
      expectContinue - true if a 100-continue response is expected.
      Returns:
      A Response.Builder with the response headers.
      Throws:
      IOException - if an I/O error occurs.
    • reportedContentLength

      public long reportedContentLength(Response response)
      Reports the content length of the response.
      Specified by:
      reportedContentLength in interface HttpCodec
      Parameters:
      response - The response.
      Returns:
      The content length.
    • openResponseBodySource

      public org.miaixz.bus.core.io.source.Source openResponseBodySource(Response response)
      Opens a source to read the response body.
      Specified by:
      openResponseBodySource in interface HttpCodec
      Parameters:
      response - The response.
      Returns:
      A source for reading the response body.
    • trailers

      public Headers trailers() throws IOException
      Returns the trailers of the response.
      Specified by:
      trailers in interface HttpCodec
      Returns:
      The response trailers.
      Throws:
      IOException - if an I/O error occurs.
    • cancel

      public void cancel()
      Cancels the stream.
      Specified by:
      cancel in interface HttpCodec