diff --git a/cmd/httpx/httpx.go b/cmd/httpx/httpx.go index bb96c6f..e1a418b 100644 --- a/cmd/httpx/httpx.go +++ b/cmd/httpx/httpx.go @@ -34,6 +34,7 @@ func main() { httpxOptions.FollowHostRedirects = options.FollowHostRedirects httpxOptions.HttpProxy = options.HttpProxy + var key, value string httpxOptions.CustomHeaders = make(map[string]string) for _, customHeader := range options.CustomHeaders { tokens := strings.Split(customHeader, ":") @@ -41,8 +42,10 @@ func main() { if len(tokens) < 2 { continue } + key = strings.TrimSpace(tokens[0]) + value = strings.TrimSpace(tokens[1]) - httpxOptions.CustomHeaders[tokens[0]] = tokens[1] + httpxOptions.CustomHeaders[key] = value } hp, err := httpx.New(&httpxOptions) diff --git a/common/httpx/httpx.go b/common/httpx/httpx.go index 1304d94..dfb150e 100644 --- a/common/httpx/httpx.go +++ b/common/httpx/httpx.go @@ -92,14 +92,12 @@ func New(options *Options) (*HTTPX, error) { // Do http request func (h *HTTPX) Do(req *retryablehttp.Request) (*Response, error) { - var ( - resp Response - ) httpresp, err := h.client.Do(req) if err != nil { return nil, err } + var resp Response resp.Headers = httpresp.Header.Clone() // httputil.DumpResponse does not handle websockets @@ -181,5 +179,9 @@ func (h *HTTPX) NewRequest(method, URL string) (req *retryablehttp.Request, err func (h *HTTPX) SetCustomHeaders(r *retryablehttp.Request, headers map[string]string) { for name, value := range headers { r.Header.Set(name, value) + // host header is particular + if strings.ToLower(name) == "host" { + r.Host = value + } } }