Play Framework 2.1中的AbsoluteURI支持

And*_*rey 13 scala routes playframework playframework-2.1

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

为了允许在未来版本的HTTP中转换为所有请求中的absoluteURI,所有HTTP/1.1服务器必须接受请求中的absoluteURI表单,即使HTTP/1.1客户端只会在对代理的请求中生成它们.

我有客户端将POST请求发送到我的play-2.1.1服务器.他这样发送:

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...
Run Code Online (Sandbox Code Playgroud)

所有请求都会被"未找到操作"错误拒绝.我使用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
Run Code Online (Sandbox Code Playgroud)

我在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)
}
Run Code Online (Sandbox Code Playgroud)

通过此解决方法,我的客户端的所有请求都得到了正确处理.

那么,在Play Framework中有更简单的方法吗?或者这是唯一的方法吗?

Ric*_*rty 1

感谢@nraychaudhuri Play 2.2 支持absoluteURI-style 请求标头。

这是问题和拉取请求:https ://github.com/playframework/playframework/pull/1060