aboutsummaryrefslogtreecommitdiff
path: root/http.go
diff options
context:
space:
mode:
authorGravatar Tolyar <Tolyar@users.noreply.github.com> 2021-12-17 08:26:17 +0300
committerGravatar GitHub <noreply@github.com> 2021-12-17 06:26:17 +0100
commit4517204499caef79d5a956cc816e5f0903f0ff6d (patch)
tree4b499dcf745d6492269ae9ac407786ec531e3705 /http.go
parentfix: reset response after reset user values on keep-alive connections (#1176) (diff)
downloadfasthttp-4517204499caef79d5a956cc816e5f0903f0ff6d.tar.gz
fasthttp-4517204499caef79d5a956cc816e5f0903f0ff6d.tar.bz2
fasthttp-4517204499caef79d5a956cc816e5f0903f0ff6d.zip
Allow to set Host header for Client (#1169)
* Allow to set Host header for Client * Allow to change Host header without tests violation * Rename AllowToChangeHostHeader and add tests. * Allow to use empty uri.Host() when req.Header.Host() does not empty
Diffstat (limited to 'http.go')
-rw-r--r--http.go14
1 files changed, 11 insertions, 3 deletions
diff --git a/http.go b/http.go
index 530cbc5..81b2496 100644
--- a/http.go
+++ b/http.go
@@ -56,6 +56,9 @@ type Request struct {
// Request timeout. Usually set by DoDeadline or DoTimeout
// if <= 0, means not set
timeout time.Duration
+
+ // Use Host header (request.Header.SetHost) instead of the host from SetRequestURI, SetHost, or URI().SetHost
+ UseHostHeader bool
}
// Response represents HTTP response.
@@ -1394,10 +1397,15 @@ func (req *Request) Write(w *bufio.Writer) error {
if len(req.Header.Host()) == 0 || req.parsedURI {
uri := req.URI()
host := uri.Host()
- if len(host) == 0 {
- return errRequestHostRequired
+ if len(req.Header.Host()) == 0 {
+ if len(host) == 0 {
+ return errRequestHostRequired
+ } else {
+ req.Header.SetHostBytes(host)
+ }
+ } else if !req.UseHostHeader {
+ req.Header.SetHostBytes(host)
}
- req.Header.SetHostBytes(host)
req.Header.SetRequestURIBytes(uri.RequestURI())
if len(uri.username) > 0 {