Class HeaderInterceptor

java.lang.Object
com.shri.restinpeace.interceptor.HeaderInterceptor
All Implemented Interfaces:
RequestInterceptor

public class HeaderInterceptor extends Object implements 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 Details

    • HeaderInterceptor

      public HeaderInterceptor(String name, String value)
      Injects a single header with a static value.
      Parameters:
      name - the header name
      value - the static header value
    • HeaderInterceptor

      public HeaderInterceptor(String name, Supplier<String> valueSupplier)
      Injects a single header whose value is re-evaluated for each request.
      Parameters:
      name - the header name
      valueSupplier - supplies the header value for each request
    • HeaderInterceptor

      public HeaderInterceptor(Map<String,Supplier<String>> valueSuppliers)
      Injects several headers, each re-evaluated for every request.
      Parameters:
      valueSuppliers - a header name to value-supplier map, applied to every request
  • Method Details