When developing golang http application, I use http.Request
a lot. When accessing request host address, I would use req.Host
, but I find that there is
Essentially http.Request.Host
is for convenience.
r.Host
is much easier to call than r.Header.Get("Host")
or r.URL.Host
.
Also to be noted that some routers strip the host from http.Request.URL
so http.Request.Host
is useful in those cases as well.
Hence it can be considered that req.Host provides the Host value even when the request header or url has been modified elsewhere.