Class RequestOptionsBuilder

java.lang.Object
com.linecorp.armeria.client.RequestOptionsBuilder
All Implemented Interfaces:
RequestOptionsSetters

public final class RequestOptionsBuilder extends Object implements RequestOptionsSetters
A builder for creating a new RequestOptions.
  • Method Details

    • responseTimeout

      public RequestOptionsBuilder responseTimeout(Duration responseTimeout)
      Description copied from interface: RequestOptionsSetters
      Schedules the response timeout that is triggered when the Response is not fully received within the specified Duration since the Response started or Request was fully sent. Duration.ZERO disables the limit.
      Specified by:
      responseTimeout in interface RequestOptionsSetters
    • responseTimeoutMillis

      public RequestOptionsBuilder responseTimeoutMillis(long responseTimeoutMillis)
      Description copied from interface: RequestOptionsSetters
      Schedules the response timeout that is triggered when the Response is not fully received within the specified responseTimeoutMillis since the Response started or Request was fully sent. 0 disables the limit.
      Specified by:
      responseTimeoutMillis in interface RequestOptionsSetters
    • writeTimeout

      public RequestOptionsBuilder writeTimeout(Duration writeTimeout)
      Description copied from interface: RequestOptionsSetters
      Sets the amount of time allowed until the initial write attempt of the current Request succeeds. Duration.ZERO disables the limit.
      Specified by:
      writeTimeout in interface RequestOptionsSetters
    • writeTimeoutMillis

      public RequestOptionsBuilder writeTimeoutMillis(long writeTimeoutMillis)
      Description copied from interface: RequestOptionsSetters
      Sets the amount of time allowed until the initial write attempt of the current Request succeeds. 0 disables the limit.
      Specified by:
      writeTimeoutMillis in interface RequestOptionsSetters
    • maxResponseLength

      public RequestOptionsBuilder maxResponseLength(long maxResponseLength)
      Description copied from interface: RequestOptionsSetters
      Sets the maximum allowed length of a server response in bytes. 0 disables the limit.
      Specified by:
      maxResponseLength in interface RequestOptionsSetters
    • requestAutoAbortDelay

      public RequestOptionsBuilder requestAutoAbortDelay(Duration delay)
      Description copied from interface: RequestOptionsSetters
      Sets the amount of time to wait before aborting an HttpRequest when its corresponding HttpResponse is complete. This may be useful when you want to send additional data even after the response is complete. Specify Duration.ZERO to abort the HttpRequest immediately. Any negative value will not abort the request automatically. There is no delay by default.
      Specified by:
      requestAutoAbortDelay in interface RequestOptionsSetters
    • requestAutoAbortDelayMillis

      public RequestOptionsBuilder requestAutoAbortDelayMillis(long delayMillis)
      Description copied from interface: RequestOptionsSetters
      Sets the amount of time in millis to wait before aborting an HttpRequest when its corresponding HttpResponse is complete. This may be useful when you want to send additional data even after the response is complete. Specify 0 to abort the HttpRequest immediately. Any negative value will not abort the request automatically. There is no delay by default.
      Specified by:
      requestAutoAbortDelayMillis in interface RequestOptionsSetters
    • attr

      public <V> RequestOptionsBuilder attr(io.netty.util.AttributeKey<V> key, @Nullable V value)
      Description copied from interface: RequestOptionsSetters
      Associates the specified value with the given AttributeKey in this request. If this context previously contained a mapping for the AttributeKey, the old value is replaced by the specified value.
      Specified by:
      attr in interface RequestOptionsSetters
    • exchangeType

      public RequestOptionsBuilder exchangeType(ExchangeType exchangeType)
      Description copied from interface: RequestOptionsSetters
      Sets the ExchangeType that determines whether to stream an HttpRequest or HttpResponse. Note that an HttpRequest will be aggregated before being written if ExchangeType.UNARY or ExchangeType.RESPONSE_STREAMING is set. If unspecified, the Clients try to infer a proper ExchangeType depending on the content type of a request and a response. Here are examples:

      WebClient

      
       WebClient client = WebClient.of("https://armeria.dev");
      
       try (ClientRequestContextCaptor captor = Clients.newContextCaptor()) {
           client.prepare()
                 .post("/api/v1/items")
                 .contentJson(new Item(...)) // A non-streaming request type.
                 .asString()                 // A non-streaming response type.
                 .execute();
           assert captor.get().exchangeType() == ExchangeType.UNARY;
       }
      
       try (ClientRequestContextCaptor captor = Clients.newContextCaptor()) {
           client.get("/api/v1/items")   // A non-streaming request type.
                 .aggregate();           // A return type is not specified; Assuming that response streaming
                                         // is enabled.
           assert captor.get().exchangeType() == ExchangeType.RESPONSE_STREAMING;
       }
      
       try (ClientRequestContextCaptor captor = Clients.newContextCaptor()) {
           client.prepare()
                 .post("/api/v1/items")
                 .content(MediaType.JSON_LINES, StreamMessage.of(...)) // A streaming request type.
                 .asFile(Path.get("/path/to/destination"))             // A streaming response type.
                 .execute();
           assert captor.get().exchangeType() == ExchangeType.BIDI_STREAMING;
       }
       

      BlockingWebClient

      Since a request and a response of BlockingWebClient are fully aggregated, ExchangeType.UNARY is only supported.

      
       try (ClientRequestContextCaptor captor = Clients.newContextCaptor()) {
           AggregatedHttpResponse response = client.blocking().get("/api/v1/items");
           assert captor.get().exchangeType() == ExchangeType.UNARY;
       }
       

      gRPC clients

      An ExchangeType is automatically inferred from the io.grpc.MethodDescriptor.MethodType.

      
       try (ClientRequestContextCaptor captor = Clients.newContextCaptor()) {
           Response response = grpcClient.unaryCall(...);
           assert captor.get().exchangeType() == ExchangeType.UNARY;
       }
       

      Thrift clients

      Thrift protocols do not support streaming. ExchangeType.UNARY is only supported.

      Specified by:
      exchangeType in interface RequestOptionsSetters
    • build

      public RequestOptions build()
      Returns a newly created RequestOptions with the properties specified so far.