我正在尝试编写一个可以使用任何类型的内容并从请求中获取原始内容的micronaut端点,并且面临着两个挑战:
我尝试了以下方法:
@Controller(value = "/test", consumes = "*/*")
public class MyController {
@Post("/one")
public String one(HttpRequest<?> req) {
// req.getHeaders() returns expected headers
// req.getParameters() seems to be fine
// req.getBody(...) always return null regardless of which getBody method I use. I used the debugger to study what `req` contains and saw the underlying netty content appears empty
}
@Post("/two")
public String two(HttpHeaders headers, HttpParameters params, @Body Object value) {
// headers & params are good
// body gives me a CompositeByteBuf... I find it surprising micronaut "leaks" the underlying netty bytebuf to the higher level impl
}
}
注意事项:
-H "Content-Type: */*"
时,我才能击中这些端点。我希望无论Content-Type
的值如何,这些端点都是可以到达的。答案 0 :(得分:1)
通配符是问题所在,我能够使处理程序#1与HttpRequest<String>
一起使用:
@Post("/one")
public String one(HttpRequest<String> req) { ...
,尽管consumes="*/*"
,处理程序仍然不接受任何内容类型的请求。我向项目提交了一个问题:https://github.com/micronaut-projects/micronaut-core/issues/2334