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

Processing of charset in Content-Type Header not case-insensitive #29416

Closed
mpapenbr opened this issue Nov 2, 2022 · 3 comments
Closed

Processing of charset in Content-Type Header not case-insensitive #29416

mpapenbr opened this issue Nov 2, 2022 · 3 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@mpapenbr
Copy link

mpapenbr commented Nov 2, 2022

Affects: 6.0.0-RC2


Given the following Controller:

record RequestData(String msg){};

@RestController
public class SampleController {
	@PostMapping(value = "/", consumes = "application/vnd.demo-v1.0+json;charset=utf-8")
	public String sample(@RequestBody RequestData data) {
		return "Success " + data.msg();
	}
}

When accessing this endpoint via curl I get different behaviours for the following requests:

Success: (when using lower case utf-8)

$ curl -v localhost:8080 -H "Content-type: application/vnd.demo-v1.0+json;charset=utf-8" -d '{"msg": "hello"}'
*   Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST / HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.84.0
> Accept: */*
> Content-type: application/vnd.demo-v1.0+json;charset=utf-8
> Content-Length: 16
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200
< Content-Type: text/plain;charset=UTF-8
< Content-Length: 13
< Date: Wed, 02 Nov 2022 09:19:15 GMT
<
Success hello* Connection #0 to host localhost left intact

Failure: (when using upper case UTF-8)

$ curl -v localhost:8080 -H "Content-type: application/vnd.demo-v1.0+json;charset=UTF-8" -d '{"msg": "hello"}'
*   Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST / HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.84.0
> Accept: */*
> Content-type: application/vnd.demo-v1.0+json;charset=UTF-8
> Content-Length: 16
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 415
< Accept: application/vnd.demo-v1.0+json;charset=utf-8
< Content-Type: application/json
< Transfer-Encoding: chunked
< Date: Wed, 02 Nov 2022 09:18:57 GMT
<
{"timestamp":"2022-11-02T09:18:57.530+00:00","status":415,"error":"Unsupported Media Type","path":"/"}* Connection #0 to host localhost left intact

This behavior is new with the 6.0 stream. With 5.3 both requests delivered a 200 response.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 2, 2022
@poutsma
Copy link
Contributor

poutsma commented Nov 2, 2022

I think this is due to the fix for #28024.

@rstoyanchev Thoughts? Should we do a case insensitive comparison instead?

@rstoyanchev
Copy link
Contributor

Yes, I think that would make sense.

@rstoyanchev rstoyanchev added this to the 6.0.0-RC3 milestone Nov 2, 2022
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 2, 2022
@poutsma poutsma self-assigned this Nov 2, 2022
@poutsma
Copy link
Contributor

poutsma commented Nov 2, 2022

Looks like we used equalsIgnoreCase before this was refactored because of #28024, see

if (StringUtils.hasText(s1) && StringUtils.hasText(s2) && !s1.equalsIgnoreCase(s2)) {
.

@poutsma poutsma closed this as completed in 9e30615 Nov 2, 2022
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

4 participants