Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/protocols/http/utils.go
2070 views
1
package http
2
3
import (
4
"io"
5
"strings"
6
7
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/generators"
8
"github.com/projectdiscovery/rawhttp"
9
"github.com/projectdiscovery/utils/errkit"
10
)
11
12
// dump creates a dump of the http request in form of a byte slice
13
func dump(req *generatedRequest, reqURL string) ([]byte, error) {
14
if req.request != nil {
15
// Use a clone to avoid a race condition with the http transport
16
bin, err := req.request.Clone(req.request.Context()).Dump()
17
if err != nil {
18
return nil, errkit.Wrapf(err, "could not dump request: %v", req.request.String())
19
}
20
return bin, nil
21
}
22
rawHttpOptions := &rawhttp.Options{CustomHeaders: req.rawRequest.UnsafeHeaders, CustomRawBytes: req.rawRequest.UnsafeRawBytes}
23
bin, err := rawhttp.DumpRequestRaw(req.rawRequest.Method, reqURL, req.rawRequest.Path, generators.ExpandMapValues(req.rawRequest.Headers), io.NopCloser(strings.NewReader(req.rawRequest.Data)), rawHttpOptions)
24
if err != nil {
25
return nil, errkit.Wrapf(err, "could not dump request: %v", reqURL)
26
}
27
return bin, nil
28
}
29
30