2020-12-29 01:30:07 +05:30
|
|
|
package http
|
|
|
|
|
|
|
|
|
|
import (
|
2021-06-09 11:15:21 +05:30
|
|
|
"io"
|
2020-12-29 01:30:07 +05:30
|
|
|
"strings"
|
|
|
|
|
|
2023-10-17 17:44:13 +05:30
|
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/generators"
|
2020-12-29 01:30:07 +05:30
|
|
|
"github.com/projectdiscovery/rawhttp"
|
2024-03-13 20:35:19 +05:30
|
|
|
errorutil "github.com/projectdiscovery/utils/errors"
|
2020-12-29 01:30:07 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// dump creates a dump of the http request in form of a byte slice
|
|
|
|
|
func dump(req *generatedRequest, reqURL string) ([]byte, error) {
|
|
|
|
|
if req.request != nil {
|
2024-03-13 20:35:19 +05:30
|
|
|
bin, err := req.request.Dump()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, errorutil.NewWithErr(err).WithTag("http").Msgf("could not dump request: %v", req.request.URL.String())
|
|
|
|
|
}
|
|
|
|
|
return bin, nil
|
2020-12-29 01:30:07 +05:30
|
|
|
}
|
2022-05-27 18:23:07 +02:00
|
|
|
rawHttpOptions := &rawhttp.Options{CustomHeaders: req.rawRequest.UnsafeHeaders, CustomRawBytes: req.rawRequest.UnsafeRawBytes}
|
2024-03-13 20:35:19 +05:30
|
|
|
bin, err := rawhttp.DumpRequestRaw(req.rawRequest.Method, reqURL, req.rawRequest.Path, generators.ExpandMapValues(req.rawRequest.Headers), io.NopCloser(strings.NewReader(req.rawRequest.Data)), rawHttpOptions)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, errorutil.NewWithErr(err).WithTag("http").Msgf("could not dump request: %v", reqURL)
|
|
|
|
|
}
|
|
|
|
|
return bin, nil
|
2020-12-29 01:30:07 +05:30
|
|
|
}
|