Search code examples
netflix-feignnetflix-ribbon

Feign + Ribbon request interception AFTER target host is choosen


What I'm currently doing (which is very simple and convenient way):

Feign.builder()
.client(RibbonClient.create())
...
.requestInterceptor(new MyInterceptor())

But interception occur before ribbon actually resolve target host. Problem is, that one header that I want to add, have to be created based on the name of the target host.

Is there anyway I can manipulate headers after host is resolved?


Solution

  • I have found following solution for this problem. Instead of using Feign interceptor I use RibbonClient delegate:

    Feign.builder()
    .client(RibbonClient.builder().delegate(new MyDelegate())
    ...
    

    MyDelegate extends feign.Client.Default class and overrides public Response execute(Request request, Request.Options options) method.

    In this way I can access target host by URI.create(request.url()).getHost().

    Then I create new Request, add my header and run super.execute(newRequest, options) as the last instruction.