Go的默認HTTP服務器實現合併斜槓的HTTP請求,返回一個HTTP重定向迴應「清理」路徑:重寫Go的默認HTTP Sever的重定向行爲
https://code.google.com/p/go/source/browse/src/pkg/net/http/server.go#1420
所以,如果你犯了一個HTTP請求GET /http://foo.com/
,服務器迴應301 Moved Permanently ... Location: /http:/foo.com/
。
我想禁用這種行爲並自己處理所有路徑。
我是一個Go新手,看起來好像我可以創建自己的Server
實例並覆蓋Handler
屬性,但我不知道該怎麼做?
哇,這竟然是真的很簡單 - 我會花更多的時間在接口和類型讀了!以下是我結束的實施:https://gist.github.com/johnboxall/5698940 –
@jb。你不需要空的struct,關閉會執行https://gist.github.com/tsenart/5fc18c659814c078378d –