spring-cloud/spring-cloud-openfeign

Response body null when Request contains body (For 401 responses)

PedroAmLemos opened this issue · 2 comments

Describe the bug
Using <spring-cloud.version>2023.0.3</spring-cloud.version>

When I make a OpenFeign client that does not have a body, the 401 response contains a not null body but if I add a body parameter the returned Response.Body comes empty.

Sample

@FeignClient(name = "example", url = "http://localhost:8080")
public interface Example {
    @PostMapping(value = "/post", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    ResponseEntity<String> exec(
            @RequestHeader("X-A") String a,
            @RequestBody String jsonBody
    );

this produces

feign.FeignException$Unauthorized: [401] during [POST] to [http://localhost:8080/post] [example#exec(String,String)]: []

but after removing the jasonBody attribute, I get:

feign.FeignException$Unauthorized: [401] during [POST] to [http://localhost:8080/post] [example#exec(String)]: [RETURNED BODY]

This is the controller I used to test it:

    @PostMapping(path = "/post", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    ResponseEntity<String> post(@RequestHeader("X-A") String A,String body) {
        System.out.println("request received, header " + A + " body: " + body);
        return new ResponseEntity<>("RETURNED BODY", HttpStatus.UNAUTHORIZED);

    }
pxpy commented

It seems like the controller problem. The parameter of jsonBody don't have @RequestBody annatation.

@pxpy You are right! I guess the service I'm making a request to, has the same fault on their controllers. Thanks!