diff --git a/pkg/protocols/http/httpclientpool/options.go b/pkg/protocols/http/httpclientpool/options.go index b6e60b636..f24e421b8 100644 --- a/pkg/protocols/http/httpclientpool/options.go +++ b/pkg/protocols/http/httpclientpool/options.go @@ -7,6 +7,7 @@ import ( "time" "github.com/projectdiscovery/rawhttp" + urlutil "github.com/projectdiscovery/utils/url" ) // WithCustomTimeout is a configuration for custom timeout @@ -39,7 +40,27 @@ func SendRawRequest(client *rawhttp.Client, opts *RawHttpRequestOpts) (*http.Res // this error is caused when rawhttp client sends a corrupted or malformed request packet to server // some servers may attempt gracefully shutdown but most will just abruptly close the connection which results // in a connection reset by peer error and this can be safely assumed as 400 Bad Request in terms of normal http flow - req, _ := http.NewRequest(opts.Method, opts.URL, opts.Body) + req, reqErr := http.NewRequest(opts.Method, opts.URL, opts.Body) + if reqErr != nil { + // failed to build new request mostly because of invalid url or body + // try again or else return urlErr + parsed, urlErr := urlutil.ParseAbsoluteURL(opts.URL, true) + if urlErr != nil { + return nil, err + } + req, reqErr = http.NewRequest(opts.Method, parsed.Host, opts.Body) + if reqErr != nil { + return nil, err + } + req.URL = parsed.URL + req.Header = opts.Headers + } + + // if req is still nil, return error + if req == nil { + return nil, err + } + req.Header = opts.Headers resp = &http.Response{ Request: req,