在Ruby/Rack中,我能夠get the scheme of the current request URL from scheme#request
。然而,在圍棋,http.Request.URL.Scheme
返回一個空字符串:獲取當前請求URL的方案
package main
import (
"fmt"
"log"
"net/http"
)
func main() {
http.HandleFunc("/", handler)
log.Fatal(http.ListenAndServe(":8080", nil))
}
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "%#v\n", r.URL.Scheme) // Always shows empty string
}
我怎樣才能把當前請求的URL的方案?
您可以檢查'r.Proto'它將返回HTTP/1.1或HTTP/2文件,但不知道它是否會爲HTTPS –