Dynamic Headers not set at all when using @Param or @HeaderMap annotation with FormEncoder | Feign Builder
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.8k
- Forks
- 1.9k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 41
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the FormEncoder and SpringFormEncoder handling of the @HeaderMap or @Param request shown in the issue, especially how Content-Type is read before encoding. Verify the request-building path and existing multipart tests, if present. Done means dynamic headers are available to the encoder while multipart Content-Type still receives its charset and boundary.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100