簡體   English   中英

Play Framework 2.1中的AbsoluteURI支持

[英]AbsoluteURI support in Play Framework 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...

所有請求都會被“未找到操作”錯誤拒絕。 我使用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

我在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 Play 2.2支持absoluteURI風格的請求標頭。

這是問題和拉取請求: https//github.com/playframework/playframework/pull/1060

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM