feign
Interface RequestInterceptor
- All Known Implementing Classes:
- BasicAuthRequestInterceptor
public interface RequestInterceptor
Zero or more RequestInterceptors
may be configured for purposes
such as adding headers to all requests. No guarantees are give with regards
to the order that interceptors are applied. Once interceptors are applied,
Target.apply(RequestTemplate)
is called to create the immutable http
request sent via Client.execute(Request, feign.Request.Options)
.
For example:
public void apply(RequestTemplate input) {
input.replaceHeader("X-Auth", currentToken);
}
Configuration
RequestInterceptors
are configured via Dagger
set
or
set values
provider
methods.
For example:
@Provides(Type = SET) RequestInterceptor addTimestamp(TimestampInterceptor in) {
return in;
}
Implementation notes
Do not add parameters, such as /path/{foo}/bar
in your implementation of apply(RequestTemplate)
.
Interceptors are applied after the template's parameters are
resolved
. This is to ensure
that you can implement signatures are interceptors.
Relationship to Retrofit 1.x
This class is similar to RequestInterceptor.intercept()
,
except that the implementation can read, remove, or otherwise mutate any
part of the request template.
apply
void apply(RequestTemplate template)
- Called for every request. Add data using methods on the supplied
RequestTemplate
.