java.lang.Object
org.miaixz.bus.http.metric.http.Http1Codec
- All Implemented Interfaces:
HttpCodec
可以用来发送HTTP/1.1消息的套接字连接。这个类严格执行以下生命周期: 没有请求主体的交换器可以跳过创建和关闭请求主体。没有响应体的交换器可以 调用
newFixedLengthSource(0) 并可以跳过读取和关闭该源- 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
ConstructorsConstructorDescriptionHttp1Codec(Httpd httpd, RealConnection realConnection, org.miaixz.bus.core.io.source.BufferSource source, org.miaixz.bus.core.io.sink.BufferSink sink) -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()取消这个流。返回携带此编解码器的连接org.miaixz.bus.core.io.sink.SinkcreateRequestBody(Request request, long contentLength) 返回一个可以对请求体进行流处理的输出流.void将请求刷新到基础套接字,就不会传输更多的字节.void将请求刷新到基础套接字booleanisClosed()Returns true if this connection is closed.org.miaixz.bus.core.io.source.SourceopenResponseBodySource(Response response) readResponseHeaders(boolean expectContinue) 从HTTP传输解析响应头的字节longreportedContentLength(Response response) voidskipConnectBody(Response response) The response body from a CONNECT should be empty, but if it is not then we should consume it before proceeding.trailers()在HTTP响应之后返回voidwriteRequest(Headers headers, String requestLine) Returns bytes of a request header for sending on an HTTP transport.voidwriteRequestHeaders(Request request) Prepares the HTTP headers and sends them to the server.
-
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
Description copied from interface:HttpCodec返回携带此编解码器的连接- Specified by:
connectionin interfaceHttpCodec
-
createRequestBody
public org.miaixz.bus.core.io.sink.Sink createRequestBody(Request request, long contentLength) throws IOException Description copied from interface:HttpCodec返回一个可以对请求体进行流处理的输出流.- Specified by:
createRequestBodyin interfaceHttpCodec- Parameters:
request- 网络请求contentLength- 内容长度- Returns:
- 缓冲信息
- Throws:
IOException
-
cancel
public void cancel()Description copied from interface:HttpCodec取消这个流。这个流所持有的资源将被清理,尽管不是同步的。这可能会在连接池线程之后发生 -
writeRequestHeaders
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 theContent-Lengthheader field receives the proper value.- Specified by:
writeRequestHeadersin interfaceHttpCodec- Parameters:
request- 网络请求- Throws:
IOException- 异常
-
reportedContentLength
- Specified by:
reportedContentLengthin interfaceHttpCodec
-
openResponseBodySource
- Specified by:
openResponseBodySourcein interfaceHttpCodec
-
trailers
Description copied from interface:HttpCodec在HTTP响应之后返回 -
isClosed
public boolean isClosed()Returns true if this connection is closed. -
flushRequest
Description copied from interface:HttpCodec将请求刷新到基础套接字- Specified by:
flushRequestin interfaceHttpCodec- Throws:
IOException- 异常
-
finishRequest
Description copied from interface:HttpCodec将请求刷新到基础套接字,就不会传输更多的字节.- Specified by:
finishRequestin interfaceHttpCodec- Throws:
IOException- 异常
-
writeRequest
Returns bytes of a request header for sending on an HTTP transport.- Throws:
IOException
-
readResponseHeaders
Description copied from interface:HttpCodec从HTTP传输解析响应头的字节- Specified by:
readResponseHeadersin interfaceHttpCodec- Parameters:
expectContinue- 如果这是一个带有“100”响应代码的中间响应, 则返回null。否则,此方法永远不会返回null.- Returns:
- 响应构建器
- Throws:
IOException- 异常
-
skipConnectBody
The response body from a CONNECT should be empty, but if it is not then we should consume it before proceeding.- Throws:
IOException
-