spring-projects / spring-projects/spring-framework

WebFlux returns 406 but Spring MVC renders "text/plain" request based on Publisher<?> and String [SPR-17078]

Open
#21,615 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: web type: enhancement
Dominant language
Java
Stars
60.2k
Forks
38.8k
Avg merge
5d 2h
Merged PRs (30d)
27

Description

Dave Syer opened SPR-17078 and commented

I assume this is a Framework issue (might be Spring Boot I guess, since that's what I use to test it).

Controller:

@GetMapping("/straight")
public Mono<ResponseEntity<Publisher<?>>> straight() {
     return Mono.just(ResponseEntity.ok().header("x-foo", "spam")
               .body(Mono.from(Flux.just("foo", "bar"))));
}

Test:

@Test
public void straight() throws Exception {
     ResponseEntity<String> result = rest.exchange(RequestEntity
               .get(new URI("/straight")).accept(MediaType.TEXT_PLAIN).build(),
               String.class);
     assertThat(result.getBody()).isEqualTo("foo");
     assertThat(result.getHeaders()).containsKey("x-foo");
}

The test passes with MVC and fails with Webflux (406 not acceptable).


Affects: 5.0.7

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 by reproducing the supplied /straight controller and straight test on Spring MVC and WebFlux with version 5.0.7, focusing on the ResponseEntity containing a Publisher<?> and the text/plain request. Trace the WebFlux response handling after the 406 occurs. Done means the WebFlux case matches the MVC result, including the foo body and x-foo header.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.