Reputation: 1636
I am trying to send a custom host header using feign client, but the consumer application is not picking them. I am using spring boot feign and not openfeign.
Apart from Host, everyother header seems to be working as expected.
ResponseEntity<JSONObject> list(@PathVariable("name") String name,
@RequestParam("id") String id, @RequestParam("modelName") String modelName,
@RequestHeader(value = "Authorization", required = true) String authorizationHeader,
@RequestHeader(value = "Host", required = true) String hostName);
When i pass hostname as "xyz.com" the consumer application is still taking default host header.
In Consumer code when i read value of Host header from controller class, i do not get zyz.com. instead it picks from dns name.
Upvotes: 2
Views: 3019
Reputation: 301
you can try System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
to allow usage of restricted headers
see https://github.com/OpenFeign/feign/issues/747
Upvotes: 0
Reputation: 36
The solution is included in the springframework. Add in the your property file:
feign.okhttp.enabled = true
And add the dependency of okhttp3, example in pom
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
You can find more informations here
Upvotes: 0
Reputation: 49
Same problem happened for me - the @Param
and @Headers
didn't work for the "Host" header.
Two things that I changed solved the issue - use OkHttpClient
, and add a requestInterceptor
when building the client:
client = Feign.builder()
.client(new OkHttpClient())
.requestInterceptor(request -> request.header("Host", hostHeaderValue))
.target(MyClient.class, url);
Upvotes: 1