- All Known Implementing Classes:
Http1Codec,Http2Codec
public interface HttpCodec
Encodes HTTP requests and decodes HTTP responses.
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe timeout to use when discarding an input stream. -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()Cancels this stream.Returns the connection that carries this codec.org.miaixz.bus.core.io.sink.SinkcreateRequestBody(Request request, long contentLength) Returns an output stream that can stream the request body.voidFlushes the request to the underlying socket, indicating that no more bytes will be transmitted.voidFlushes the request to the underlying socket.org.miaixz.bus.core.io.source.SourceopenResponseBodySource(Response response) Opens a source to read the response body.readResponseHeaders(boolean expectContinue) Parses the response headers from the HTTP transport.longreportedContentLength(Response response) Returns the reported content length of the response.trailers()Returns the trailer headers after the HTTP response.voidwriteRequestHeaders(Request request) Writes the request headers to the network.
-
Field Details
-
DISCARD_STREAM_TIMEOUT_MILLIS
static final int DISCARD_STREAM_TIMEOUT_MILLISThe 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
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
Flushes the request to the underlying socket.- Throws:
IOException- if an I/O error occurs.
-
finishRequest
Flushes the request to the underlying socket, indicating that no more bytes will be transmitted.- Throws:
IOException- if an I/O error occurs.
-
readResponseHeaders
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
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
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
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.
-