Class Http1Codec

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

public class Http1Codec extends Object implements HttpCodec
可以用来发送HTTP/1.1消息的套接字连接。这个类严格执行以下生命周期: 没有请求主体的交换器可以跳过创建和关闭请求主体。没有响应体的交换器可以 调用newFixedLengthSource(0) 并可以跳过读取和关闭该源
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • Http1Codec

      public Http1Codec(Httpd httpd, RealConnection realConnection, org.miaixz.bus.core.io.source.BufferSource source, org.miaixz.bus.core.io.sink.BufferSink sink)
  • Method Details

    • connection

      public RealConnection connection()
      Description copied from interface: HttpCodec
      返回携带此编解码器的连接
      Specified by:
      connection in interface HttpCodec
    • createRequestBody

      public org.miaixz.bus.core.io.sink.Sink createRequestBody(Request request, long contentLength) throws IOException
      Description copied from interface: HttpCodec
      返回一个可以对请求体进行流处理的输出流.
      Specified by:
      createRequestBody in interface HttpCodec
      Parameters:
      request - 网络请求
      contentLength - 内容长度
      Returns:
      缓冲信息
      Throws:
      IOException
    • cancel

      public void cancel()
      Description copied from interface: HttpCodec
      取消这个流。这个流所持有的资源将被清理,尽管不是同步的。这可能会在连接池线程之后发生
      Specified by:
      cancel in interface HttpCodec
    • writeRequestHeaders

      public void writeRequestHeaders(Request request) throws IOException
      Prepares the HTTP headers and sends them to the server. For streaming requests with a body, headers must be prepared before the output stream has been written to. Otherwise the body would need to be buffered! For non-streaming requests with a body, headers must be prepared after the output stream has been written to and closed. This ensures that the Content-Length header field receives the proper value.
      Specified by:
      writeRequestHeaders in interface HttpCodec
      Parameters:
      request - 网络请求
      Throws:
      IOException - 异常
    • reportedContentLength

      public long reportedContentLength(Response response)
      Specified by:
      reportedContentLength in interface HttpCodec
    • openResponseBodySource

      public org.miaixz.bus.core.io.source.Source openResponseBodySource(Response response)
      Specified by:
      openResponseBodySource in interface HttpCodec
    • trailers

      public Headers trailers()
      Description copied from interface: HttpCodec
      在HTTP响应之后返回
      Specified by:
      trailers in interface HttpCodec
      Returns:
      the object
    • isClosed

      public boolean isClosed()
      Returns true if this connection is closed.
    • flushRequest

      public void flushRequest() throws IOException
      Description copied from interface: HttpCodec
      将请求刷新到基础套接字
      Specified by:
      flushRequest in interface HttpCodec
      Throws:
      IOException - 异常
    • finishRequest

      public void finishRequest() throws IOException
      Description copied from interface: HttpCodec
      将请求刷新到基础套接字,就不会传输更多的字节.
      Specified by:
      finishRequest in interface HttpCodec
      Throws:
      IOException - 异常
    • writeRequest

      public void writeRequest(Headers headers, String requestLine) throws IOException
      Returns bytes of a request header for sending on an HTTP transport.
      Throws:
      IOException
    • readResponseHeaders

      public Response.Builder readResponseHeaders(boolean expectContinue) throws IOException
      Description copied from interface: HttpCodec
      从HTTP传输解析响应头的字节
      Specified by:
      readResponseHeaders in interface HttpCodec
      Parameters:
      expectContinue - 如果这是一个带有“100”响应代码的中间响应, 则返回null。否则,此方法永远不会返回null.
      Returns:
      响应构建器
      Throws:
      IOException - 异常
    • skipConnectBody

      public void skipConnectBody(Response response) throws IOException
      The response body from a CONNECT should be empty, but if it is not then we should consume it before proceeding.
      Throws:
      IOException