Package com.linecorp.armeria.client
Interface RequestPreparationSetters
- All Superinterfaces:
HttpMessageSetters
,PathAndQueryParamSetters
- All Known Implementing Classes:
BlockingWebClientRequestPreparation
,FutureTransformingRequestPreparation
,RestClientPreparation
,TransformingRequestPreparation
,WebClientRequestPreparation
@UnstableApi
public interface RequestPreparationSetters
extends PathAndQueryParamSetters, HttpMessageSetters
Provides the setters for building an
HttpRequest
and RequestOptions
.-
Method Summary
Modifier and TypeMethodDescription<V> com.linecorp.armeria.client.RequestOptionsSetters
attr
(AttributeKey<V> key, V value) Associates the specified value with the givenAttributeKey
in this request.com.linecorp.armeria.client.RequestOptionsSetters
exchangeType
(ExchangeType exchangeType) com.linecorp.armeria.client.RequestOptionsSetters
maxResponseLength
(long maxResponseLength) Sets the maximum allowed length of a server response in bytes.requestOptions
(RequestOptions requestOptions) Sets the specifiedRequestOptions
that could overwrite the previously configured values such asresponseTimeout(Duration)
,writeTimeout(Duration)
,maxResponseLength(long)
andattr(AttributeKey, Object)
.com.linecorp.armeria.client.RequestOptionsSetters
responseTimeout
(Duration responseTimeout) com.linecorp.armeria.client.RequestOptionsSetters
responseTimeoutMillis
(long responseTimeoutMillis) com.linecorp.armeria.client.RequestOptionsSetters
writeTimeout
(Duration writeTimeout) Sets the amount of time allowed until the initial write attempt of the currentRequest
succeeds.com.linecorp.armeria.client.RequestOptionsSetters
writeTimeoutMillis
(long writeTimeoutMillis) Sets the amount of time allowed until the initial write attempt of the currentRequest
succeeds.Methods inherited from interface com.linecorp.armeria.common.HttpMessageSetters
content, content, content, content, content, content, content, content, contentJson, cookie, cookies, header, headers, trailer, trailers
Methods inherited from interface com.linecorp.armeria.common.PathAndQueryParamSetters
disablePathParams, pathParam, pathParams, queryParam, queryParams
-
Method Details
-
requestOptions
Sets the specifiedRequestOptions
that could overwrite the previously configured values such asresponseTimeout(Duration)
,writeTimeout(Duration)
,maxResponseLength(long)
andattr(AttributeKey, Object)
. -
responseTimeout
Schedules the response timeout that is triggered when theResponse
is not fully received within the specifiedDuration
since theResponse
started orRequest
was fully sent.Duration.ZERO
disables the limit. -
responseTimeoutMillis
com.linecorp.armeria.client.RequestOptionsSetters responseTimeoutMillis(long responseTimeoutMillis) -
writeTimeout
Sets the amount of time allowed until the initial write attempt of the currentRequest
succeeds.Duration.ZERO
disables the limit. -
writeTimeoutMillis
com.linecorp.armeria.client.RequestOptionsSetters writeTimeoutMillis(long writeTimeoutMillis) Sets the amount of time allowed until the initial write attempt of the currentRequest
succeeds.0
disables the limit. -
maxResponseLength
com.linecorp.armeria.client.RequestOptionsSetters maxResponseLength(long maxResponseLength) Sets the maximum allowed length of a server response in bytes.0
disables the limit. -
attr
Associates the specified value with the givenAttributeKey
in this request. If this context previously contained a mapping for theAttributeKey
, the old value is replaced by the specified value. -
exchangeType
@UnstableApi com.linecorp.armeria.client.RequestOptionsSetters exchangeType(ExchangeType exchangeType) Sets theExchangeType
that determines whether to stream anHttpRequest
orHttpResponse
. Note that anHttpRequest
will be aggregated before being written ifExchangeType.UNARY
orExchangeType.RESPONSE_STREAMING
is set. If unspecified, theClient
s try to infer a properExchangeType
depending on the content type of a request and a response. Here are examples: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; }
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 theio.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.
-