3

Given this simple controller, it appears Micronaut is rejecting requests with a "415 Unsupported Media Type" based on the request's content type header on a GET request.

@Controller
class BadController() {

    @Get("/blah")
    @Produces("image/svg+xml")
    fun getBlah(): HttpResponse<*> {
        return HttpResponse.ok("</some-svg>")
    }
}

For example:

curl -v http://localhost:8080/blah -H "Content-Type: text/plain" 
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> GET /blah HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.54.0
> Accept: */*
> Content-Type: text/plain
> 
< HTTP/1.1 415 Unsupported Media Type
< Date: Mon, 7 Jan 2019 16:31:48 GMT
< transfer-encoding: chunked
< connection: close
< 
* Closing connection 0

MDN's content-type header doco makes it sound like the header wouldn't even be used by the server for GET's because the client isn't sending content:

In requests, (such as POST or PUT), the client tells the server what type of data is actually sent.

https://web.archive.org/web/20210816145541/https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type

imxitiz
  • 3,920
  • 3
  • 9
  • 33
  • It doesn't make sense to send a content type for a GET request (https://stackoverflow.com/questions/5661596/do-i-need-a-content-type-for-http-get-requests) – Sascha Frinken Jan 08 '19 at 16:54
  • The server should be able to answer and discard the pieces correctly, according to the HTTP specification. Erlang's Cowboy HTTP server does not behave in such a way, so something downstream is weird here. – x80486 Jan 08 '19 at 17:59
  • JMeter is the client sending the content type on GET requests. Spring correctly ignored the content type, but Micronaut doesn't. – Eric Runquist Jan 08 '19 at 19:42
  • 1
    Running `curl -v http://localhost:8080/blah -H "Content-Type;"` to get an empty content type causes an internal server error in Micronaut. – Eric Runquist Jan 08 '19 at 20:19

0 Answers0