Skip to content

HTTP request with invalid "Accept" header causes HTTP 500 #30979

Closed as not planned
@maio

Description

@maio

Steps to reproduce:

  1. Create new app at https://start.spring.io/ with Spring Web dependency - config
  2. Start the app ./gradlew bootRun
  3. 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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: external-projectNeeds a fix in external projectin: webIssues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions