В Ruby/Rack я могу get the scheme of the current request URL from scheme#request
. Однако, в Go, 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 –