加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Scala – Play Framework 2.1中的AbsoluteURI支持

发布时间:2020-12-16 09:15:43 所属栏目:安全 来源:网络整理
导读:如下所述: 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 clie
如下所述:
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.

我有客户端发送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...

所有请求都被拒绝,并显示“Action not found”错误.我使用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

我在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)
}

并且这个解决方法,我的客户端的所有请求被正确处理.

那么在Play Framework中做到这一点还是比较直接的方法呢?

解决方法

感谢 @nraychaudhuri播放2.2支持absoluteURI样式的请求标头.

这是问题并提出要求:https://github.com/playframework/playframework/pull/1060

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读