3

鉴于这个简单的控制器,Micronaut 似乎正在根据 GET 请求中请求的内容类型标头拒绝具有“415 Unsupported Media Type”的请求。

@Controller
class BadController() {

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

例如:

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 的内容类型标头 doco 听起来好像标头甚至不会被服务器用于 GET,因为客户端不发送内容:

在请求中(例如 POST 或 PUT),客户端告诉服务器实际发送的数据类型。

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

4

0 回答 0