Module bus.http

Interface HttpCodec

All Known Implementing Classes:
Http1Codec, Http2Codec

public interface HttpCodec
Encodes HTTP requests and decodes HTTP responses.
Since:
Java 17+
Author:
Kimi Liu
  • Field Details

    • DISCARD_STREAM_TIMEOUT_MILLIS

      static final int DISCARD_STREAM_TIMEOUT_MILLIS
      The timeout to use when discarding an input stream. Since this is used for connection reuse, this timeout should be significantly less than the time it takes to establish a new connection.
      See Also:
  • Method Details

    • connection

      RealConnection connection()
      Returns the connection that carries this codec.
      Returns:
      The real connection.
    • createRequestBody

      org.miaixz.bus.core.io.sink.Sink createRequestBody(Request request, long contentLength) throws IOException
      Returns an output stream that can stream the request body.
      Parameters:
      request - The network request.
      contentLength - The content length of the request body.
      Returns:
      A sink for the request body.
      Throws:
      IOException - if an I/O error occurs.
    • writeRequestHeaders

      void writeRequestHeaders(Request request) throws IOException
      Writes the request headers to the network. This should update the HTTP engine's sentRequestMillis field.
      Parameters:
      request - The network request.
      Throws:
      IOException - if an I/O error occurs.
    • flushRequest

      void flushRequest() throws IOException
      Flushes the request to the underlying socket.
      Throws:
      IOException - if an I/O error occurs.
    • finishRequest

      void finishRequest() throws IOException
      Flushes the request to the underlying socket, indicating that no more bytes will be transmitted.
      Throws:
      IOException - if an I/O error occurs.
    • readResponseHeaders

      Response.Builder readResponseHeaders(boolean expectContinue) throws IOException
      Parses the response headers from the HTTP transport.
      Parameters:
      expectContinue - If this is an intermediate response with a "100" response code, this returns null. Otherwise, this method will never return null.
      Returns:
      A response builder.
      Throws:
      IOException - if an I/O error occurs.
    • reportedContentLength

      long reportedContentLength(Response response) throws IOException
      Returns the reported content length of the response.
      Parameters:
      response - The response.
      Returns:
      The reported content length.
      Throws:
      IOException - if an I/O error occurs.
    • openResponseBodySource

      org.miaixz.bus.core.io.source.Source openResponseBodySource(Response response) throws IOException
      Opens a source to read the response body.
      Parameters:
      response - The response.
      Returns:
      A source for the response body.
      Throws:
      IOException - if an I/O error occurs.
    • trailers

      Headers trailers() throws IOException
      Returns the trailer headers after the HTTP response.
      Returns:
      The trailer headers.
      Throws:
      IOException - if an I/O error occurs.
    • cancel

      void cancel()
      Cancels this stream. Resources held by this stream will be cleaned up, though not necessarily synchronously. This may happen after the connection pool thread.