问题
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:
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.
来源:https://stackoverflow.com/questions/45962233/feign-ribbon-request-interception-after-target-host-is-choosen