Package com.shri.restinpeace.interceptor
Class HeaderInterceptor
java.lang.Object
com.shri.restinpeace.interceptor.HeaderInterceptor
- All Implemented Interfaces:
RequestInterceptor
Pre-built interceptor that injects one or more headers into every request -
the common "attach an auth token (or a batch of fixed headers) to every
call" use case. Use a
Supplier (single-header constructor, or the
Map<String, Supplier<String>> constructor) when a value can change
between calls (e.g. a token that gets refreshed); use of(Map) for
a fixed set of static headers.-
Constructor Summary
ConstructorsConstructorDescriptionHeaderInterceptor(String name, String value) Injects a single header with a static value.HeaderInterceptor(String name, Supplier<String> valueSupplier) Injects a single header whose value is re-evaluated for each request.HeaderInterceptor(Map<String, Supplier<String>> valueSuppliers) Injects several headers, each re-evaluated for every request. -
Method Summary
Modifier and TypeMethodDescriptionvoidbeforeRequest(RequestContext context) Called before the request is sent.static HeaderInterceptorCreates an interceptor for a fixed set of static headers.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.shri.restinpeace.interceptor.RequestInterceptor
afterResponse, shortCircuit
-
Constructor Details
-
HeaderInterceptor
Injects a single header with a static value.- Parameters:
name- the header namevalue- the static header value
-
HeaderInterceptor
Injects a single header whose value is re-evaluated for each request.- Parameters:
name- the header namevalueSupplier- supplies the header value for each request
-
HeaderInterceptor
Injects several headers, each re-evaluated for every request.- Parameters:
valueSuppliers- a header name to value-supplier map, applied to every request
-
-
Method Details
-
of
Creates an interceptor for a fixed set of static headers.- Parameters:
headers- a header name to value map, applied to every request- Returns:
- the interceptor
-
beforeRequest
Description copied from interface:RequestInterceptorCalled before the request is sent. Can add headers viaRequestContext.addHeader(java.lang.String, java.lang.String), or abort the call by throwing.- Specified by:
beforeRequestin interfaceRequestInterceptor- Parameters:
context- the request being made
-