Module methanol

Class RedirectingInterceptor

  • All Implemented Interfaces:
    Methanol.Interceptor

    public final class RedirectingInterceptor
    extends java.lang.Object
    implements Methanol.Interceptor
    An Methanol.Interceptor that follows redirects. The interceptor is applied prior to the cache interceptor only if one is installed. Allowing the cache to intercept redirects increases its efficiency as network access can be avoided in case a redirected URI is accessed repeatedly (provided the redirecting response is cacheable). Additionally, this ensures correctness in case a cacheable response is received for a redirected request. In such case, the response should be cached for the URI the request was redirected to, not the initiating URI.

    For best compatibility, the interceptor follows HttpClient's redirecting behaviour.

    • Constructor Summary

      Constructors 
      Constructor Description
      RedirectingInterceptor​(java.net.http.HttpClient.Redirect policy, java.util.concurrent.Executor handlerExecutor)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> java.net.http.HttpResponse<T> intercept​(java.net.http.HttpRequest request, Methanol.Interceptor.Chain<T> chain)
      Intercepts given request and returns the resulting response, usually by forwarding to the given chain.
      <T> java.util.concurrent.CompletableFuture<java.net.http.HttpResponse<T>> interceptAsync​(java.net.http.HttpRequest request, Methanol.Interceptor.Chain<T> chain)
      Intercepts the given request and returns a CompletableFuture for the resulting response, usually by forwarding to the given chain.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RedirectingInterceptor

        public RedirectingInterceptor​(java.net.http.HttpClient.Redirect policy,
                                      java.util.concurrent.Executor handlerExecutor)
    • Method Detail

      • intercept

        public <T> java.net.http.HttpResponse<T> intercept​(java.net.http.HttpRequest request,
                                                           Methanol.Interceptor.Chain<T> chain)
                                                    throws java.io.IOException,
                                                           java.lang.InterruptedException
        Description copied from interface: Methanol.Interceptor
        Intercepts given request and returns the resulting response, usually by forwarding to the given chain.
        Specified by:
        intercept in interface Methanol.Interceptor
        Throws:
        java.io.IOException
        java.lang.InterruptedException
      • interceptAsync

        public <T> java.util.concurrent.CompletableFuture<java.net.http.HttpResponse<T>> interceptAsync​(java.net.http.HttpRequest request,
                                                                                                        Methanol.Interceptor.Chain<T> chain)
        Description copied from interface: Methanol.Interceptor
        Intercepts the given request and returns a CompletableFuture for the resulting response, usually by forwarding to the given chain.
        Specified by:
        interceptAsync in interface Methanol.Interceptor