我不敢相信这不在http4s documentation中,并且我能够在网上挖掘的示例代码(在探索了足够长的时间发现UrlForm类之后)对我不起作用。
相关代码如下所示:
case req @ POST -> Root / "compose" =>
req.decode[UrlForm] { ps =>
println("ps.values: " + ps.values)
val content = ps.getFirstOrElse("content",
throw new IllegalStateException("No content given!"))
// Do something with `content`...
}提交关联表单时,将抛出IllegalStateException。ps.values是一个空映射(Map())。
正如预期的那样,我可以(使用println)看到Content-Type是application/x-www-form-urlencoded,并且我可以从浏览器的Network选项卡中看到请求“paramater”(编码的表单值)正在正确发送。
发布于 2020-02-19 02:04:54
问题是我有一个在HttpServletRequest上调用getParameterMap的过滤器(javax.servlet.Filter)。这正在耗尽请求的InputStream,并且在请求传递到servlet (BlockingHttp4sServlet)实例之前就发生了。
在我看来,当BlockingHttp4sServlet接收到IllegalStateException返回true的InputStream时,它应该引发一个isFinished (或者更具描述性的东西)。(我在Github上使用了http4s项目的filed an issue。)
https://stackoverflow.com/questions/59912146
复制相似问题