Feign + Ribbon request interception AFTER target host is choosen

615 views Asked by At

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?

1

There are 1 answers

0
Purple On BEST ANSWER

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.