public final class RedirectConfigBuilder
extends Object
RedirectConfig.| Constructor and Description |
|---|
RedirectConfigBuilder() |
| Modifier and Type | Method and Description |
|---|---|
RedirectConfigBuilder |
allowedMethods(HttpRequestMethod... methods)
Sets
HttpRequestMethods that are allowed to follow redirects. |
RedirectConfigBuilder |
allowedStatuses(HttpResponseStatus... statuses)
Sets
HttpResponseStatuses that are allowed to follow redirects. |
RedirectConfigBuilder |
allowNonRelativeRedirects(boolean allowNonRelativeRedirects)
Allows non-relative redirects (if supported by the underlying client implementation).
|
RedirectConfig |
build()
Builds a new
RedirectConfig. |
RedirectConfigBuilder |
changePostToGet(boolean changePostToGet)
Enforces change of the request method from
POST to
GET for subsequent requests for
301 (Moved Permanently) and
302 (Found) status codes. |
RedirectConfigBuilder |
headersToRedirect(CharSequence... headerNames)
Configures headers that have to be copied from the original request on each non-relative redirect.
|
RedirectConfigBuilder |
locationMapper(BiFunction<HttpRequestMetaData,HttpResponseMetaData,String> locationMapper)
|
RedirectConfigBuilder |
maxRedirects(int maxRedirects)
Sets the maximum number of redirects to follow.
|
RedirectConfigBuilder |
redirectPayloadBody(boolean redirectPayloadBody)
Allows redirecting payload body of the original request on each non-relative redirect.
|
RedirectConfigBuilder |
redirectPredicate(RedirectConfig.RedirectPredicate predicate)
Sets a predicate for an additional check to decide if the redirect should be performed or not based on the given
context.
|
RedirectConfigBuilder |
redirectRequestTransformer(RedirectConfig.RedirectRequestTransformer transformer)
Sets a transformer to apply further modifications for the redirect request after it was initialized.
|
RedirectConfigBuilder |
trailersToRedirect(CharSequence... trailerNames)
Configures trailers that have to be copied from the original request on each non-relative redirect.
|
public RedirectConfigBuilder maxRedirects(int maxRedirects)
maxRedirects - The maximum number of redirects to followthispublic RedirectConfigBuilder allowedStatuses(HttpResponseStatus... statuses)
HttpResponseStatuses that are allowed to follow redirects.
All statuses must belong to REDIRECTION_3XX status class.
statuses - HttpResponseStatuses that are allowed to follow redirectsthispublic RedirectConfigBuilder allowedMethods(HttpRequestMethod... methods)
HttpRequestMethods that are allowed to follow redirects.methods - HttpRequestMethods that are allowed to follow redirectsthispublic RedirectConfigBuilder allowNonRelativeRedirects(boolean allowNonRelativeRedirects)
Notes:
MultiAddressHttpClientBuilder. If a client is limited to only one target host/port/scheme, it will
follow only relative redirects.headersToRedirect(CharSequence...),
redirectPayloadBody(boolean), trailersToRedirect(CharSequence...), or
redirectRequestTransformer(RedirectConfig.RedirectRequestTransformer) if headers or message body
should be preserved.allowNonRelativeRedirects - If true, redirection will follow non-relative locations (if supported by
the underlying client implementation)thisMultiAddressHttpClientBuilder,
headersToRedirect(CharSequence...),
redirectPayloadBody(boolean),
trailersToRedirect(CharSequence...),
redirectRequestTransformer(RedirectConfig.RedirectRequestTransformer)public RedirectConfigBuilder locationMapper(BiFunction<HttpRequestMetaData,HttpResponseMetaData,String> locationMapper)
response,
optionally considering the previous request as well.
Per RFC7231, section 7.1.2 3xx (Redirection)
responses use Location header value as the preferred target resource for
automatically redirecting the request. However, the target resource can be identified by a custom header or a
combination of previous request and 3xx (Redirection) response meta-data.
locationMapper - A function to extract redirect location information. If the function returns null,
redirection response won't be followedthispublic RedirectConfigBuilder redirectPredicate(RedirectConfig.RedirectPredicate predicate)
predicate - RedirectConfig.RedirectPredicate for an additional check to decide if the redirect should be
performed or not based on the given contextthismaxRedirects(int),
allowedMethods(HttpRequestMethod...),
allowNonRelativeRedirects(boolean)public RedirectConfigBuilder changePostToGet(boolean changePostToGet)
POST to
GET for subsequent requests for
301 (Moved Permanently) and
302 (Found) status codes.
For historical reasons, RFC7231 sections
6.4.2 and
6.4.3 allow user agents to change the
request method from POST to GET for the subsequent
request. If this behavior is undesired, this option can be turned off or
307 (Temporary Redirect) and
308 (Permanent Redirect) status codes can be used instead.
changePostToGet - if true, request method will change from POST
to GET while following
301 (Moved Permanently) or
302 (Found) redirect status codesthispublic RedirectConfigBuilder headersToRedirect(CharSequence... headerNames)
Note: for security reasons, redirection should not automatically copy any headers from the original request when
it performs a non-relative redirect. For relative redirects, everything is copied by default. Use
redirectRequestTransformer(RedirectConfig.RedirectRequestTransformer) if more customization required.
headerNames - Names of headers that have to be copied on each non-relative redirectthisallowNonRelativeRedirects(boolean),
redirectPayloadBody(boolean),
trailersToRedirect(CharSequence...),
redirectRequestTransformer(RedirectConfig.RedirectRequestTransformer)public RedirectConfigBuilder redirectPayloadBody(boolean redirectPayloadBody)
Note: for security reasons, redirection should not automatically copy payload body of the original request when
it performs a non-relative redirect. For relative redirects, everything is copied by default. Use
redirectRequestTransformer(RedirectConfig.RedirectRequestTransformer) if more customization required.
Note: This option expects that the redirected requests have a
payload body that is
replayable, i.e. multiple subscribes to
the payload Publisher observe the same data. Publishers that do not emit any data or which are
created from in-memory data are typically replayable.
redirectPayloadBody - If true, payload body of the original request will be repeated for each
non-relative redirectthisallowNonRelativeRedirects(boolean),
headersToRedirect(CharSequence...),
trailersToRedirect(CharSequence...),
redirectRequestTransformer(RedirectConfig.RedirectRequestTransformer)public RedirectConfigBuilder trailersToRedirect(CharSequence... trailerNames)
Note: for security reasons, redirection should not automatically copy any trailers from the original request when
it performs a non-relative redirect. For relative redirects, everything is copied by default. Use
redirectRequestTransformer(RedirectConfig.RedirectRequestTransformer) if more customization required.
trailerNames - Names of trailers that have to be copied on each non-relative redirectthisallowNonRelativeRedirects(boolean),
headersToRedirect(CharSequence...),
redirectPayloadBody(boolean),
redirectRequestTransformer(RedirectConfig.RedirectRequestTransformer)public RedirectConfigBuilder redirectRequestTransformer(RedirectConfig.RedirectRequestTransformer transformer)
It can be used to add/remove headers, payload body, or trailers.
transformer - RedirectConfig.RedirectRequestTransformer that modifies a request for redirectthisheadersToRedirect(CharSequence...),
redirectPayloadBody(boolean),
trailersToRedirect(CharSequence...)public RedirectConfig build()
RedirectConfig.RedirectConfig