Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit Content-Type Header in WebClient is overwritten by ResourceHttpMessageWriter #24366

Closed
hgarus opened this issue Jan 15, 2020 · 0 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@hgarus
Copy link

hgarus commented Jan 15, 2020

I discovered this on spring-boot 2.1 I can reproduce the same behaviour using spring-boot 2.2.2.

I'm trying to post binary Content with a specified Content-Type Header using WebClient:

 WebClient.create().post().uri(MY_URI)
                .contentType(MediaType.APPLICATION_PDF)
                .body(BodyInserters.fromResource(myResource))
                .exchange()

in some cases the request was made with Content-Type: application/octet-stream instead of application/pdf.
Apparently the RessourceHttpMessageWriter will set the Content-Type Header based on the resources filename overwriting the explicitly set contentType on the Request in ResourceHttpMessageWriter.writeResource.

See https://github.com/hgarus/webclient-content-type-example/blob/master/src/test/java/com/example/demo/WebClientContentTypeTest.java for a minimal testcase.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 15, 2020
@rstoyanchev rstoyanchev self-assigned this Jan 16, 2020
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 16, 2020
@rstoyanchev rstoyanchev added this to the 5.2.4 milestone Jan 16, 2020
@rstoyanchev rstoyanchev changed the title WebClient explicit Content-Type Header is overwritten by ResourceHttpMessageWriter Explicit Content-Type Header in WebClient is overwritten by ResourceHttpMessageWriter Jan 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants