fix: server access logs contain the protocol used between the server and the load balancer, but not the protocol used between the client and the load balancer

This commit is contained in:
houseme 2022-03-09 17:42:56 +08:00
parent 8f326dcac5
commit 920dbbef5e

View File

@ -225,7 +225,8 @@ func (r *Request) GetRemoteIp() string {
// GetUrl returns current URL of this request.
func (r *Request) GetUrl() string {
scheme := "http"
if r.TLS != nil {
proto := r.Header.Get("X-Forwarded-Proto")
if r.TLS != nil || (proto != "" && strings.ToLower(proto) == "https") {
scheme = "https"
}
return fmt.Sprintf(`%s://%s%s`, scheme, r.Host, r.URL.String())