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

Add an option to not include Charset in the final http request ContentType Header #22971

Closed
tamimcsedu19 opened this issue May 14, 2019 · 2 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@tamimcsedu19
Copy link

tamimcsedu19 commented May 14, 2019

I had the following problem when using RestTemplate. The FormHttpMessageConverter always adds the charset like this application/x-www-form-urlencoded; charset=UTF-8. But, the service I was consuming was malfunctioning if I give the charset like this. It was working with just application/x-www-form-urlencoded without the charset parameter. This is an external service, so I do not have control over it.

How I solved it

I subclassed MediaType, HttpHeaders and HttpEntity, so that the getMediaType method in FormHttpMessageConverter do not try to create a new MediaType with parameters.

What I am proposing

I think there should be a property in the FormHttpMessageConverter includeCharset. We do the charset validation as usual, but before writing the ContentType, we check the flag to exclude the parameter.

I am happy to give a PR if this sounds okay.

@philwebb
Copy link
Member

The FormHttpMessageConverter is part of Spring Framework so I'll transfer the issue for that team to consider.

@philwebb philwebb transferred this issue from spring-projects/spring-boot May 14, 2019
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label May 14, 2019
@sbrannen sbrannen added the in: web Issues in web modules (web, webmvc, webflux, websocket) label May 14, 2019
@poutsma poutsma self-assigned this Nov 26, 2019
@poutsma poutsma removed the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 26, 2019
@poutsma poutsma added this to the 5.2.2 milestone Nov 26, 2019
@poutsma poutsma added the type: enhancement A general enhancement label Nov 26, 2019
@poutsma
Copy link
Contributor

poutsma commented Nov 26, 2019

Rather than adding another property which would be used by few people, I exposed the method that adds the charset. This way, you can override that method to do what you want.

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: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

5 participants