OpenFeign / OpenFeign/feign

JAXRS Handling of Accept header can lead to problems with response body decoding

Open
#1,973 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

proposal
Dominant language
Java
Stars
9.8k
Forks
1.9k
Avg merge
1d 2h
Merged PRs (30d)
41

Description

Problem scenario

The problem occurs if you have an endpoint interface method that defines multiple values @Produces annotation, e. g.:

@Produces({"application/xml", "application/json"})

When you define an explicit decoder for the feign client, e. g. JacksonDecoder, this can result in a runtime error if the server actually sends the response in the wrong format (e. g. XML in this example). I think, the behaviour is even non-deterministic in this scenario.

Problem cause

The method "handleProducesAnnotation" of the class "JAXRSContract.java" adds both produces values to the "Accept" header, which is incorrect from my point fo view. This was different in older versions (including 9.7.0), where only the first value in the @Produces annotation was added as the Accept header.

I think, the implementation should be reverted to the previous logic or at lease the bheaviour should be configurable. However, I don't see any benefits to include to 2 different values in the Accept header, as then the client needs to provide a decoder, which can handle both. This probably possibe in case of xml and json, but there can be other media types, which make it impossible to decide, which decoder to use.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in JAXRSContract.java at handleProducesAnnotation and compare its Accept-header behavior with version 9.7.0. Reproduce the endpoint using multiple @Produces values and an explicit JacksonDecoder, then verify the chosen behavior prevents a response in the wrong format from causing decoding errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.