2020-12-29 01:30:07 +05:30
|
|
|
package http
|
|
|
|
|
|
|
|
|
|
import (
|
2025-08-20 05:28:23 +05:30
|
|
|
"fmt"
|
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"
|
2025-08-20 05:28:23 +05:30
|
|
|
"github.com/projectdiscovery/utils/errkit"
|
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 {
|
2025-07-15 02:34:29 -05:00
|
|
|
// Use a clone to avoid a race condition with the http transport
|
|
|
|
|
bin, err := req.request.Clone(req.request.Context()).Dump()
|
2024-03-13 20:35:19 +05:30
|
|
|
if err != nil {
|
2025-08-20 05:28:23 +05:30
|
|
|
return nil, errkit.New(fmt.Sprintf("http: could not dump request: %v: %s", req.request.String(), err)).Build()
|
2024-03-13 20:35:19 +05:30
|
|
|
}
|
|
|
|
|
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 {
|
2025-08-20 05:28:23 +05:30
|
|
|
return nil, errkit.New(fmt.Sprintf("http: could not dump request: %v: %s", reqURL, err)).Build()
|
2024-03-13 20:35:19 +05:30
|
|
|
}
|
|
|
|
|
return bin, nil
|
2020-12-29 01:30:07 +05:30
|
|
|
}
|