I am using a Spring-Web application using jetty:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
Assume this http endpoint:
@RestController
public class ExampleController {
@GetMapping(value = "/example", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ExampleResponse example() {
return new ExampleResponse();
}
public static class ExampleResponse {
private String dummy = "example";
public String getDummy() {
return dummy;
}
}
}
and curl against the Endpoint and inspect the header curl -v localhost:8080/example
:
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /example HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Tue, 08 Oct 2019 13:52:10 GMT
< Content-Type: application/json;charset=utf-8
< Transfer-Encoding: chunked
<
* Connection #0 to host localhost left intact
Notice the charset=**utf-8**
in the response header, but I am setting the header via the annotation produces=MediaType.APPLICATION_JSON_UTF8_VALUE
to the value application/json;charset=UTF-8
. So Jetty (using tomcat everything works fine) lowercases the charset in the response header.
Why is that a problem? Some people working against my endpoints and validate this with a JSON Valiadtor (like: https://jsonformatter.curiousconcept.com/).
This validator expects the charset in UPPERCASE. (See https://stackoverflow.com/a/48466826/3046582). So what can I do about this?
Update:
like @Kayaman says System.setProperty("org.eclipse.jetty.http.HttpGenerator.STRICT", "true");
bevor the Spring-Application run wil fix this.
I also found a workaround: MimeTypes.CACHE.remove("application/json;charset=utf-8");
will solve this.