Steps to reproduce:
- Create new app at https://start.spring.io/ with
Spring Web
dependency - config - Start the app
./gradlew bootRun
- Send HTTP request
curl -I -H "Accept: yaml" http://localhost:8080/some-path
Expected response: HTTP 400 bad request (or similar) Actual response: HTTP 500 - internal server error
2023-08-02T16:10:16.524+02:00 ERROR 6385 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.http.InvalidMediaTypeException: Invalid mime type "yaml": does not contain '/'] with root cause
org.springframework.util.InvalidMimeTypeException: Invalid mime type "yaml": does not contain '/'
at org.springframework.util.MimeTypeUtils.parseMimeTypeInternal(MimeTypeUtils.java:229) ~[spring-core-6.1.0-M3.jar:6.1.0-M3]
at org.springframework.util.ConcurrentLruCache.get(ConcurrentLruCache.java:100) ~[spring-core-6.1.0-M3.jar:6.1.0-M3]
at org.springframework.util.MimeTypeUtils.parseMimeType(MimeTypeUtils.java:213) ~[spring-core-6.1.0-M3.jar:6.1.0-M3]
at org.springframework.http.MediaType.parseMediaType(MediaType.java:739) ~[spring-web-6.1.0-M3.jar:6.1.0-M3]
at org.springframework.http.MediaType.parseMediaTypes(MediaType.java:768) ~[spring-web-6.1.0-M3.jar:6.1.0-M3]
at org.springframework.boot.autoconfigure.web.servlet.WelcomePageHandlerMapping.getAcceptedMediaTypes(WelcomePageHandlerMapping.java:82) ~[spring-boot-autoconfigure-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
at org.springframework.boot.autoconfigure.web.servlet.WelcomePageHandlerMapping.isHtmlTextAccepted(WelcomePageHandlerMapping.java:71) ~[spring-boot-autoconfigure-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
at org.springframework.boot.autoconfigure.web.servlet.WelcomePageHandlerMapping.getHandlerInternal(WelcomePageHandlerMapping.java:67) ~[spring-boot-autoconfigure-3.2.0-SNAPSHOT.jar:3.2.0-SNAPSHOT]
Comment From: ASDasd341
can i look into it?
Comment From: rstoyanchev
The MediaType
parsing code raises InvalidMediaTypeException
and it's up to the calling code decide how to handle that. In this case it's Boot's WelcomePageHandlerMapping
that needs to decide what should be done, whether to ignore it, or handle it, or raise another exception that would be handled as a 400 error.
We handle InvalidMediaTypeException
in various places in Spring MVC and WebFlux. Sometimes we ignore it, and sometimes we raise HttpMediaTypeNotSupportedException
which becomes a 400.
So I think this issue belongs in Boot's issue tracker. Not much we can do from our end.
Comment From: bclozel
duplicates spring-projects/spring-boot/issues/37118