Package com.microsoft.rest.interceptors
Class CustomHeadersInterceptor
- java.lang.Object
-
- com.microsoft.rest.interceptors.CustomHeadersInterceptor
-
- All Implemented Interfaces:
okhttp3.Interceptor
public final class CustomHeadersInterceptor extends Object implements okhttp3.Interceptor
An instance of this class enables adding custom headers in client requests when added to theOkHttpClientinterceptors.
-
-
Constructor Summary
Constructors Constructor Description CustomHeadersInterceptor()Initialize an instance ofCustomHeadersInterceptorclass.CustomHeadersInterceptor(String key, String value)Initialize an instance ofCustomHeadersInterceptorclass.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CustomHeadersInterceptoraddHeader(String name, String value)Add a single header key-value pair.CustomHeadersInterceptoraddHeaderMap(Map<String,String> headers)Add all headers in a header map.CustomHeadersInterceptoraddHeaderMultimap(Map<String,List<String>> headers)Add all headers in a header multimap.CustomHeadersInterceptoraddHeaders(okhttp3.Headers headers)Add all headers in aHeadersobject.Map<String,List<String>>headers()okhttp3.Responseintercept(okhttp3.Interceptor.Chain chain)CustomHeadersInterceptorremoveHeader(String name)Remove a header.CustomHeadersInterceptorreplaceHeader(String name, String value)Add a single header key-value pair.
-
-
-
Constructor Detail
-
CustomHeadersInterceptor
public CustomHeadersInterceptor()
Initialize an instance ofCustomHeadersInterceptorclass.
-
CustomHeadersInterceptor
public CustomHeadersInterceptor(String key, String value)
Initialize an instance ofCustomHeadersInterceptorclass.- Parameters:
key- the key for the headervalue- the value of the header
-
-
Method Detail
-
replaceHeader
public CustomHeadersInterceptor replaceHeader(String name, String value)
Add a single header key-value pair. If one with the name already exists, it gets replaced.- Parameters:
name- the name of the header.value- the value of the header.- Returns:
- the interceptor instance itself.
-
addHeader
public CustomHeadersInterceptor addHeader(String name, String value)
Add a single header key-value pair. If one with the name already exists, both stay in the header map.- Parameters:
name- the name of the header.value- the value of the header.- Returns:
- the interceptor instance itself.
-
addHeaders
public CustomHeadersInterceptor addHeaders(okhttp3.Headers headers)
Add all headers in aHeadersobject.- Parameters:
headers- an OkHttpHeadersobject.- Returns:
- the interceptor instance itself.
-
addHeaderMap
public CustomHeadersInterceptor addHeaderMap(Map<String,String> headers)
Add all headers in a header map.- Parameters:
headers- a map of headers.- Returns:
- the interceptor instance itself.
-
addHeaderMultimap
public CustomHeadersInterceptor addHeaderMultimap(Map<String,List<String>> headers)
Add all headers in a header multimap.- Parameters:
headers- a multimap of headers.- Returns:
- the interceptor instance itself.
-
removeHeader
public CustomHeadersInterceptor removeHeader(String name)
Remove a header.- Parameters:
name- the name of the header to remove.- Returns:
- the interceptor instance itself.
-
intercept
public okhttp3.Response intercept(okhttp3.Interceptor.Chain chain) throws IOException- Specified by:
interceptin interfaceokhttp3.Interceptor- Throws:
IOException
-
-