java.lang.Object
org.miaixz.bus.http.accord.Exchange
Transmits a single HTTP request and a response pair. This layers connection management and events on
HttpCodec, which handles the actual I/O.- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
ConstructorsConstructorDescriptionExchange(Transmitter transmitter, NewCall call, EventListener eventListener, org.miaixz.bus.http.accord.ExchangeFinder finder, HttpCodec codec) -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()Cancels this exchange.Returns the connection for this exchange.org.miaixz.bus.core.io.sink.SinkcreateRequestBody(Request request, boolean duplex) Creates a sink to write the request body.voidRevoke this exchange's access to streams.voidFinishes writing the request to the network.voidFlushes the request to the network.booleanisDuplex()Returns true if the request body need not complete before the response body starts.Creates new streams for a WebSocket connection.voidPrevents new exchanges from being created on the current connection.voidNotifies the transmitter that there is no request body.openResponseBody(Response response) Opens a source to read the response body.readResponseHeaders(boolean expectContinue) Reads the response headers from the network.voidresponseHeadersEnd(Response response) Notifies the event listener that the response headers have been read.voidNotifies the event listener that response headers are about to be read.voidNotifies the transmitter that a timeout has occurred and the exchange should exit early.trailers()Returns the trailer headers for this exchange.voidNotifies this exchange that a WebSocket upgrade has failed.voidwriteRequestHeaders(Request request) Writes the request headers to the network.
-
Constructor Details
-
Exchange
public Exchange(Transmitter transmitter, NewCall call, EventListener eventListener, org.miaixz.bus.http.accord.ExchangeFinder finder, HttpCodec codec)
-
-
Method Details
-
connection
Returns the connection for this exchange.- Returns:
- The connection.
-
isDuplex
public boolean isDuplex()Returns true if the request body need not complete before the response body starts.- Returns:
trueif this is a duplex exchange.
-
writeRequestHeaders
Writes the request headers to the network.- Parameters:
request- The request whose headers to write.- Throws:
IOException- if an I/O error occurs.
-
createRequestBody
public org.miaixz.bus.core.io.sink.Sink createRequestBody(Request request, boolean duplex) throws IOException Creates a sink to write the request body.- Parameters:
request- The request whose body to write.duplex- Whether this is a duplex request.- Returns:
- A sink for the request body.
- Throws:
IOException- if an I/O error occurs.
-
flushRequest
Flushes the request to the network.- Throws:
IOException- if an I/O error occurs.
-
finishRequest
Finishes writing the request to the network.- Throws:
IOException- if an I/O error occurs.
-
responseHeadersStart
public void responseHeadersStart()Notifies the event listener that response headers are about to be read. -
readResponseHeaders
Reads the response headers from the network.- Parameters:
expectContinue- Whether a 100-continue response is expected.- Returns:
- A builder for the response, or null if no response is available.
- Throws:
IOException- if an I/O error occurs.
-
responseHeadersEnd
Notifies the event listener that the response headers have been read.- Parameters:
response- The response whose headers were read.
-
openResponseBody
Opens a source to read the response body.- Parameters:
response- The response whose body to open.- Returns:
- The response body.
- Throws:
IOException- if an I/O error occurs.
-
trailers
Returns the trailer headers for this exchange.- Returns:
- The trailer headers.
- Throws:
IOException- if an I/O error occurs.
-
timeoutEarlyExit
public void timeoutEarlyExit()Notifies the transmitter that a timeout has occurred and the exchange should exit early. -
newWebSocketStreams
Creates new streams for a WebSocket connection.- Returns:
- The WebSocket streams.
- Throws:
SocketException- if a socket error occurs.
-
webSocketUpgradeFailed
public void webSocketUpgradeFailed()Notifies this exchange that a WebSocket upgrade has failed. -
noNewExchangesOnConnection
public void noNewExchangesOnConnection()Prevents new exchanges from being created on the current connection. -
cancel
public void cancel()Cancels this exchange. -
detachWithViolence
public void detachWithViolence()Revoke this exchange's access to streams. This is necessary when a follow-up request is required but the preceding exchange hasn't completed yet. -
noRequestBody
public void noRequestBody()Notifies the transmitter that there is no request body.
-