2020-09-28 02:17:35 +02:00
|
|
|
package requests
|
|
|
|
|
|
|
|
|
|
import (
|
2020-10-30 12:36:16 +01:00
|
|
|
"bytes"
|
2020-09-28 02:17:35 +02:00
|
|
|
"io/ioutil"
|
|
|
|
|
"net/http/httputil"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/projectdiscovery/rawhttp"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func Dump(req *HTTPRequest, reqURL string) ([]byte, error) {
|
|
|
|
|
if req.Request != nil {
|
2020-10-30 12:36:16 +01:00
|
|
|
// Create a copy on the fly of the request body - ignore errors
|
|
|
|
|
bodyBytes, _ := req.Request.BodyBytes()
|
|
|
|
|
req.Request.Request.Body = ioutil.NopCloser(bytes.NewReader(bodyBytes))
|
2020-09-28 02:17:35 +02:00
|
|
|
return httputil.DumpRequest(req.Request.Request, true)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rawhttp.DumpRequestRaw(req.RawRequest.Method, reqURL, req.RawRequest.Path, ExpandMapValues(req.RawRequest.Headers), ioutil.NopCloser(strings.NewReader(req.RawRequest.Data)))
|
|
|
|
|
}
|