简体   繁体   English

Play Framework 2.1中的AbsoluteURI支持

[英]AbsoluteURI support in Play Framework 2.1

As stated here: http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html 如上所述: http//www.w3.org/Protocols/rfc2616/rfc2616-sec5.html

To allow for transition to absoluteURIs in all requests in future versions of HTTP, all HTTP/1.1 servers MUST accept the absoluteURI form in requests, even though HTTP/1.1 clients will only generate them in requests to proxies. 为了允许在未来版本的HTTP中转换为所有请求中的absoluteURI,所有HTTP / 1.1服务器必须在请求中接受absoluteURI表单,即使HTTP / 1.1客户端只在请求代理时生成它们。

I have client which sends POST-requests to my play-2.1.1 server. 我有客户端将POST请求发送到我的play-2.1.1服务器。 He sends it this way: 他这样发送:

POST http://172.16.1.227:9000/A8%3aF9%3a4B%3a20%3a89%3a40/1089820966/ HTTP/1.1
Content-Length: 473
Content-Type: application/json
Date: Thu, 25 Apr 2013 15:44:43 GMT
Host: 172.16.1.227:9000
User-Agent: my-client

...some data...

All requests are rejected with "Action not found" error. 所有请求都会被“未找到操作”错误拒绝。 The very same request which I send using curl is just fine and the only difference between them is curl send it with relative URI: 我使用curl发送的相同请求很好,它们之间的唯一区别是curl使用相对URI发送它:

POST /A8%3aF9%3a4B%3a20%3a89%3a40/1089820966/ HTTP/1.1
Accept: */*
Content-Length: 593
Content-Type: application/json
Host: 172.16.1.227:9000
User-Agent: curl/7.30.0

I created the following simple workaround in Global.scala: 我在Global.scala中创建了以下简单的解决方法:

override def onRouteRequest(request: RequestHeader): Option[Handler] = {
  if (request.path.startsWith("http://")) {
    super.onRouteRequest(request.copy(
      path = request.path.replace("http://"+request.host, "")
    ))
  } else super.onRouteRequest(request)
}

And with this workaround all requests from my client are handled correctly. 通过此解决方法,我的客户端的所有请求都得到了正确处理。

So, is there more straightforward way to do it in Play Framework or thats the only way? 那么,在Play Framework中有更简单的方法吗?或者这是唯一的方法吗?

Thanks to @nraychaudhuri Play 2.2 supports absoluteURI -style request headers. 感谢@nraychaudhuri Play 2.2支持absoluteURI风格的请求标头。

Here's the issue and pull request: https://github.com/playframework/playframework/pull/1060 这是问题和拉取请求: https//github.com/playframework/playframework/pull/1060

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM