Module bus.http

Class Exchange

java.lang.Object
org.miaixz.bus.http.accord.Exchange

public final class Exchange extends Object
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 Details

  • Method Details

    • connection

      public RealConnection 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:
      true if this is a duplex exchange.
    • writeRequestHeaders

      public void writeRequestHeaders(Request request) throws IOException
      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

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

      public void finishRequest() throws IOException
      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

      public Response.Builder readResponseHeaders(boolean expectContinue) throws IOException
      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

      public void responseHeadersEnd(Response response)
      Notifies the event listener that the response headers have been read.
      Parameters:
      response - The response whose headers were read.
    • openResponseBody

      public ResponseBody openResponseBody(Response response) throws IOException
      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

      public Headers trailers() throws IOException
      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

      public RealWebSocket.Streams newWebSocketStreams() throws SocketException
      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.