Merge pull request #45 from projectdiscovery/42-bugfix

fixing host header
This commit is contained in:
bauthard 2020-07-23 14:16:46 +05:30 committed by GitHub
commit 5e169282e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -34,6 +34,7 @@ func main() {
httpxOptions.FollowHostRedirects = options.FollowHostRedirects httpxOptions.FollowHostRedirects = options.FollowHostRedirects
httpxOptions.HttpProxy = options.HttpProxy httpxOptions.HttpProxy = options.HttpProxy
var key, value string
httpxOptions.CustomHeaders = make(map[string]string) httpxOptions.CustomHeaders = make(map[string]string)
for _, customHeader := range options.CustomHeaders { for _, customHeader := range options.CustomHeaders {
tokens := strings.Split(customHeader, ":") tokens := strings.Split(customHeader, ":")
@ -41,8 +42,10 @@ func main() {
if len(tokens) < 2 { if len(tokens) < 2 {
continue 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) hp, err := httpx.New(&httpxOptions)

View File

@ -92,14 +92,12 @@ func New(options *Options) (*HTTPX, error) {
// Do http request // Do http request
func (h *HTTPX) Do(req *retryablehttp.Request) (*Response, error) { func (h *HTTPX) Do(req *retryablehttp.Request) (*Response, error) {
var (
resp Response
)
httpresp, err := h.client.Do(req) httpresp, err := h.client.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
var resp Response
resp.Headers = httpresp.Header.Clone() resp.Headers = httpresp.Header.Clone()
// httputil.DumpResponse does not handle websockets // 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) { func (h *HTTPX) SetCustomHeaders(r *retryablehttp.Request, headers map[string]string) {
for name, value := range headers { for name, value := range headers {
r.Header.Set(name, value) r.Header.Set(name, value)
// host header is particular
if strings.ToLower(name) == "host" {
r.Host = value
}
} }
} }