Class RedirectConfigBuilder
RedirectConfig
.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionallowedMethods
(HttpRequestMethod... methods) SetsHttpRequestMethod
s that are allowed to follow redirects.allowedStatuses
(HttpResponseStatus... statuses) SetsHttpResponseStatus
es that are allowed to follow redirects.allowNonRelativeRedirects
(boolean allowNonRelativeRedirects) Allows non-relative redirects (if supported by the underlying client implementation).build()
Builds a newRedirectConfig
.changePostToGet
(boolean changePostToGet) Enforces change of the request method fromPOST
toGET
for subsequent requests for301 (Moved Permanently)
and302 (Found)
status codes.headersToRedirect
(CharSequence... headerNames) Configures headers that have to be copied from the original request on each non-relative redirect.locationMapper
(BiFunction<HttpRequestMetaData, HttpResponseMetaData, String> locationMapper) maxRedirects
(int maxRedirects) Sets the maximum number of redirects to follow.redirectPayloadBody
(boolean redirectPayloadBody) Allows redirecting payload body of the original request on each non-relative redirect.Sets a predicate for an additional check to decide if the redirect should be performed or not based on the given context.Sets a transformer to apply further modifications for the redirect request after it was initialized.trailersToRedirect
(CharSequence... trailerNames) Configures trailers that have to be copied from the original request on each non-relative redirect.
-
Constructor Details
-
RedirectConfigBuilder
public RedirectConfigBuilder()
-
-
Method Details
-
maxRedirects
Sets the maximum number of redirects to follow.- Parameters:
maxRedirects
- The maximum number of redirects to follow- Returns:
this
-
allowedStatuses
SetsHttpResponseStatus
es that are allowed to follow redirects.All statuses must belong to
REDIRECTION_3XX
status class.- Parameters:
statuses
-HttpResponseStatus
es that are allowed to follow redirects- Returns:
this
-
allowedMethods
SetsHttpRequestMethod
s that are allowed to follow redirects.- Parameters:
methods
-HttpRequestMethod
s that are allowed to follow redirects- Returns:
this
-
allowNonRelativeRedirects
Allows non-relative redirects (if supported by the underlying client implementation). Non-relative redirects are redirects to either a different target host/port or a different scheme.Notes:
- This option has effect only when redirections is performed by a client that is capable to communicate
with multiple target hosts or schemes, like the one which is produced by
MultiAddressHttpClientBuilder
. If a client is limited to only one target host/port/scheme, it will follow only relative redirects. - For security reasons, redirection should not automatically copy headers nor message body of the original
request for non-relative locations. Use
headersToRedirect(CharSequence...)
,redirectPayloadBody(boolean)
,trailersToRedirect(CharSequence...)
, orredirectRequestTransformer(RedirectConfig.RedirectRequestTransformer)
if headers or message body should be preserved.
- Parameters:
allowNonRelativeRedirects
- Iftrue
, redirection will follow non-relative locations (if supported by the underlying client implementation)- Returns:
this
- See Also:
- This option has effect only when redirections is performed by a client that is capable to communicate
with multiple target hosts or schemes, like the one which is produced by
-
locationMapper
public RedirectConfigBuilder locationMapper(BiFunction<HttpRequestMetaData, HttpResponseMetaData, String> locationMapper) Sets a function to extract redirect location information from the redirectresponse
, optionally considering the previousrequest
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.- Parameters:
locationMapper
- A function to extract redirect location information. If the function returnsnull
, redirection response won't be followed- Returns:
this
-
redirectPredicate
Sets a predicate for an additional check to decide if the redirect should be performed or not based on the given context.- Parameters:
predicate
-RedirectConfig.RedirectPredicate
for an additional check to decide if the redirect should be performed or not based on the given context- Returns:
this
- See Also:
-
changePostToGet
Enforces change of the request method fromPOST
toGET
for subsequent requests for301 (Moved Permanently)
and302 (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
toGET
for the subsequent request. If this behavior is undesired, this option can be turned off or307 (Temporary Redirect)
and308 (Permanent Redirect)
status codes can be used instead.- Parameters:
changePostToGet
- iftrue
, request method will change fromPOST
toGET
while following301 (Moved Permanently)
or302 (Found)
redirect status codes- Returns:
this
-
headersToRedirect
Configures headers that have to be copied from the original request on each non-relative redirect.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.- Parameters:
headerNames
- Names of headers that have to be copied on each non-relative redirect- Returns:
this
- See Also:
-
redirectPayloadBody
Allows redirecting payload body of the original request on each non-relative redirect.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 apayload body
that is replayable, i.e. multiple subscribes to the payloadPublisher
observe the same data.Publisher
s that do not emit any data or which are created from in-memory data are typically replayable.- Parameters:
redirectPayloadBody
- Iftrue
, payload body of the original request will be repeated for each non-relative redirect- Returns:
this
- See Also:
-
trailersToRedirect
Configures trailers that have to be copied from the original request on each non-relative redirect.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.- Parameters:
trailerNames
- Names of trailers that have to be copied on each non-relative redirect- Returns:
this
- See Also:
-
redirectRequestTransformer
public RedirectConfigBuilder redirectRequestTransformer(RedirectConfig.RedirectRequestTransformer transformer) Sets a transformer to apply further modifications for the redirect request after it was initialized.It can be used to add/remove headers, payload body, or trailers.
- Parameters:
transformer
-RedirectConfig.RedirectRequestTransformer
that modifies a request for redirect- Returns:
this
- See Also:
-
build
Builds a newRedirectConfig
.- Returns:
- a new
RedirectConfig
-