I am using FormEncoder because of multipart file in request. So the issue is that when feign gets to form encoder, it does not have any header set yet but in the FormEncoder class, it needs the content type to determine the content processor. If I hardcode the header using @Headers("Content-Type:....") annotation, it works fine. Also, I tried manually setting the content type to Multipart during debugging, it did get content type that time around but then it did not add 'charset' and 'boundary' in content type header which are needed for multipart requests.
So, in short, looks like the header values are not set before we go into encoder but the form encoder needs those values.
Feign versions feign-core: 12.1 feign-form-spring / feign-form: 3.8.0
Trying to use feign builder to build the client. I need headers to be dynamic.
The method of feign client looks like this: @RequestLine("POST /upload-file") Response uploadFile(@HeaderMap Map<String, Object> headerMap, MultipartFile file);
Feign.builder() .logger(new Slf4jLogger()) .errorDecoder(new DisplayDataErrorDecoder()) .retryer(Retryer.NEVER_RETRY) .encoder(new SpringFormEncoder()) .target(Some.class, url);
I am using FormEncoder because of multipart file in request. So the issue is that when feign gets to form encoder, it does not have any header set yet but in the FormEncoder class, it needs the content type to determine the content processor. If I hardcode the header using @Headers("Content-Type:....") annotation, it works fine. Also, I tried manually setting the content type to Multipart during debugging, it did get content type that time around but then it did not add 'charset' and 'boundary' in content type header which are needed for multipart requests.
So, in short, looks like the header values are not set before we go into encoder but the form encoder needs those values.