From 8ab44dcb446e8242b41a4d80b69991d36d8b832d Mon Sep 17 00:00:00 2001 From: yqiangli Date: Tue, 31 Mar 2020 21:50:15 +0800 Subject: [PATCH 1/2] Get ghttp a chance to add custom host. --- net/ghttp/ghttp_client_request.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/ghttp/ghttp_client_request.go b/net/ghttp/ghttp_client_request.go index 5689b4b3b..525210b2f 100644 --- a/net/ghttp/ghttp_client_request.go +++ b/net/ghttp/ghttp_client_request.go @@ -186,6 +186,10 @@ func (c *Client) DoRequest(method, url string, data ...interface{}) (resp *Clien // Custom header. if len(c.header) > 0 { for k, v := range c.header { + // Set host by req.Host. + if strings.ToLower(k) == "host" { + req.Host = v + } req.Header.Set(k, v) } } From 718089fc11dee2d9ec7c3cbcb317522eede6c88c Mon Sep 17 00:00:00 2001 From: yqiangli Date: Tue, 31 Mar 2020 23:28:21 +0800 Subject: [PATCH 2/2] Get ghttp a chance to add custom host. --- net/ghttp/ghttp_client_request.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/net/ghttp/ghttp_client_request.go b/net/ghttp/ghttp_client_request.go index 525210b2f..15a58eeaf 100644 --- a/net/ghttp/ghttp_client_request.go +++ b/net/ghttp/ghttp_client_request.go @@ -186,13 +186,20 @@ func (c *Client) DoRequest(method, url string, data ...interface{}) (resp *Clien // Custom header. if len(c.header) > 0 { for k, v := range c.header { - // Set host by req.Host. - if strings.ToLower(k) == "host" { - req.Host = v - } req.Header.Set(k, v) } } + // For server requests Host specifies the host on which the + // URL is sought. Per RFC 2616, this is either the value of + // the "Host" header or the host name given in the URL itself. + // It may be of the form "host:port". + // + // For client requests Host optionally overrides the Host + // header to send. If empty, the Request.Write method uses + // the value of URL.Host. + if host := req.Header.Get("Host"); host != "" { + req.Host = host + } // Custom Cookie. if len(c.cookies) > 0 { headerCookie := ""