fix panic: ref #5217 (#5230)

This commit is contained in:
Tarun Koyalwar 2024-06-02 17:11:56 +05:30 committed by GitHub
parent f8a4cf50c6
commit 8720e4f863
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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,