2020-12-26 09:25:15 +00:00
|
|
|
package http
|
|
|
|
|
2020-12-28 14:32:26 +00:00
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httputil"
|
|
|
|
"net/url"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/corpix/uarand"
|
|
|
|
"github.com/pkg/errors"
|
2020-12-28 20:00:07 +00:00
|
|
|
"github.com/projectdiscovery/gologger"
|
2020-12-28 14:32:26 +00:00
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/output"
|
2021-01-01 14:06:21 +00:00
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
|
2020-12-28 14:32:26 +00:00
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/generators"
|
2021-01-01 09:58:28 +00:00
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/tostring"
|
2020-12-28 14:32:26 +00:00
|
|
|
"github.com/projectdiscovery/rawhttp"
|
|
|
|
"github.com/remeh/sizedwaitgroup"
|
|
|
|
"go.uber.org/multierr"
|
|
|
|
)
|
|
|
|
|
|
|
|
const defaultMaxWorkers = 150
|
|
|
|
|
|
|
|
// executeRaceRequest executes race condition request for a URL
|
2021-01-01 14:06:21 +00:00
|
|
|
func (e *Request) executeRaceRequest(reqURL string, dynamicValues map[string]interface{}, callback protocols.OutputEventCallback) error {
|
2020-12-28 14:32:26 +00:00
|
|
|
generator := e.newGenerator()
|
2020-12-26 09:25:15 +00:00
|
|
|
|
|
|
|
maxWorkers := e.RaceNumberRequests
|
|
|
|
swg := sizedwaitgroup.New(maxWorkers)
|
2020-12-28 14:32:26 +00:00
|
|
|
|
|
|
|
var requestErr error
|
2020-12-30 11:19:45 +00:00
|
|
|
mutex := &sync.Mutex{}
|
2020-12-26 09:25:15 +00:00
|
|
|
|
2021-01-11 19:19:26 +00:00
|
|
|
request, err := generator.Make(reqURL, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for i := 0; i < e.RaceNumberRequests; i++ {
|
2020-12-28 14:32:26 +00:00
|
|
|
swg.Add()
|
|
|
|
go func(httpRequest *generatedRequest) {
|
2021-01-01 14:06:21 +00:00
|
|
|
err := e.executeRequest(reqURL, httpRequest, dynamicValues, callback)
|
2020-12-28 14:32:26 +00:00
|
|
|
mutex.Lock()
|
2020-12-26 09:25:15 +00:00
|
|
|
if err != nil {
|
2020-12-28 14:32:26 +00:00
|
|
|
requestErr = multierr.Append(requestErr, err)
|
2020-12-26 09:25:15 +00:00
|
|
|
}
|
2020-12-28 14:32:26 +00:00
|
|
|
mutex.Unlock()
|
|
|
|
swg.Done()
|
2020-12-26 09:25:15 +00:00
|
|
|
}(request)
|
|
|
|
}
|
|
|
|
swg.Wait()
|
2021-01-01 14:06:21 +00:00
|
|
|
return requestErr
|
2020-12-26 09:25:15 +00:00
|
|
|
}
|
|
|
|
|
2020-12-28 14:32:26 +00:00
|
|
|
// executeRaceRequest executes race condition request for a URL
|
2021-01-01 14:06:21 +00:00
|
|
|
func (e *Request) executeParallelHTTP(reqURL string, dynamicValues map[string]interface{}, callback protocols.OutputEventCallback) error {
|
2020-12-28 14:32:26 +00:00
|
|
|
generator := e.newGenerator()
|
2020-12-26 09:25:15 +00:00
|
|
|
|
|
|
|
// Workers that keeps enqueuing new requests
|
|
|
|
maxWorkers := e.Threads
|
|
|
|
swg := sizedwaitgroup.New(maxWorkers)
|
2020-12-28 14:32:26 +00:00
|
|
|
|
|
|
|
var requestErr error
|
2020-12-30 11:19:45 +00:00
|
|
|
mutex := &sync.Mutex{}
|
2020-12-28 14:32:26 +00:00
|
|
|
for {
|
|
|
|
request, err := generator.Make(reqURL, dynamicValues)
|
|
|
|
if err == io.EOF {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if err != nil {
|
2020-12-29 12:32:45 +00:00
|
|
|
e.options.Progress.DecrementRequests(int64(generator.Total()))
|
2021-01-01 14:06:21 +00:00
|
|
|
return err
|
2020-12-26 09:25:15 +00:00
|
|
|
}
|
2020-12-28 14:32:26 +00:00
|
|
|
swg.Add()
|
|
|
|
go func(httpRequest *generatedRequest) {
|
|
|
|
defer swg.Done()
|
|
|
|
|
|
|
|
e.options.RateLimiter.Take()
|
2021-01-01 14:06:21 +00:00
|
|
|
err := e.executeRequest(reqURL, httpRequest, dynamicValues, callback)
|
2020-12-28 14:32:26 +00:00
|
|
|
mutex.Lock()
|
|
|
|
if err != nil {
|
|
|
|
requestErr = multierr.Append(requestErr, err)
|
|
|
|
}
|
|
|
|
mutex.Unlock()
|
|
|
|
}(request)
|
|
|
|
e.options.Progress.IncrementRequests()
|
2020-12-26 09:25:15 +00:00
|
|
|
}
|
|
|
|
swg.Wait()
|
2021-01-01 14:06:21 +00:00
|
|
|
return requestErr
|
2020-12-26 09:25:15 +00:00
|
|
|
}
|
|
|
|
|
2020-12-28 14:32:26 +00:00
|
|
|
// executeRaceRequest executes race condition request for a URL
|
2021-01-01 14:06:21 +00:00
|
|
|
func (e *Request) executeTurboHTTP(reqURL string, dynamicValues map[string]interface{}, callback protocols.OutputEventCallback) error {
|
2020-12-28 14:32:26 +00:00
|
|
|
generator := e.newGenerator()
|
2020-12-26 09:25:15 +00:00
|
|
|
|
|
|
|
// need to extract the target from the url
|
|
|
|
URL, err := url.Parse(reqURL)
|
|
|
|
if err != nil {
|
2021-01-01 14:06:21 +00:00
|
|
|
return err
|
2020-12-26 09:25:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pipeOptions := rawhttp.DefaultPipelineOptions
|
|
|
|
pipeOptions.Host = URL.Host
|
|
|
|
pipeOptions.MaxConnections = 1
|
|
|
|
if e.PipelineConcurrentConnections > 0 {
|
|
|
|
pipeOptions.MaxConnections = e.PipelineConcurrentConnections
|
|
|
|
}
|
|
|
|
if e.PipelineRequestsPerConnection > 0 {
|
|
|
|
pipeOptions.MaxPendingRequests = e.PipelineRequestsPerConnection
|
|
|
|
}
|
|
|
|
pipeclient := rawhttp.NewPipelineClient(pipeOptions)
|
|
|
|
|
|
|
|
// defaultMaxWorkers should be a sufficient value to keep queues always full
|
|
|
|
maxWorkers := defaultMaxWorkers
|
|
|
|
// in case the queue is bigger increase the workers
|
|
|
|
if pipeOptions.MaxPendingRequests > maxWorkers {
|
|
|
|
maxWorkers = pipeOptions.MaxPendingRequests
|
|
|
|
}
|
|
|
|
swg := sizedwaitgroup.New(maxWorkers)
|
2020-12-28 14:32:26 +00:00
|
|
|
|
|
|
|
var requestErr error
|
2020-12-30 11:19:45 +00:00
|
|
|
mutex := &sync.Mutex{}
|
2020-12-28 14:32:26 +00:00
|
|
|
for {
|
|
|
|
request, err := generator.Make(reqURL, dynamicValues)
|
|
|
|
if err == io.EOF {
|
|
|
|
break
|
2020-12-26 09:25:15 +00:00
|
|
|
}
|
2020-12-28 14:32:26 +00:00
|
|
|
if err != nil {
|
2020-12-29 12:32:45 +00:00
|
|
|
e.options.Progress.DecrementRequests(int64(generator.Total()))
|
2021-01-01 14:06:21 +00:00
|
|
|
return err
|
2020-12-28 14:32:26 +00:00
|
|
|
}
|
|
|
|
request.pipelinedClient = pipeclient
|
|
|
|
|
|
|
|
swg.Add()
|
|
|
|
go func(httpRequest *generatedRequest) {
|
|
|
|
defer swg.Done()
|
2020-12-26 09:25:15 +00:00
|
|
|
|
2021-01-01 14:06:21 +00:00
|
|
|
err := e.executeRequest(reqURL, httpRequest, dynamicValues, callback)
|
2020-12-28 14:32:26 +00:00
|
|
|
mutex.Lock()
|
|
|
|
if err != nil {
|
|
|
|
requestErr = multierr.Append(requestErr, err)
|
|
|
|
}
|
|
|
|
mutex.Unlock()
|
|
|
|
}(request)
|
|
|
|
e.options.Progress.IncrementRequests()
|
2020-12-26 09:25:15 +00:00
|
|
|
}
|
|
|
|
swg.Wait()
|
2021-01-01 14:06:21 +00:00
|
|
|
return requestErr
|
2020-12-26 09:25:15 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 06:12:46 +00:00
|
|
|
// ExecuteWithResults executes the final request on a URL
|
2021-01-01 21:09:27 +00:00
|
|
|
func (r *Request) ExecuteWithResults(reqURL string, dynamicValues output.InternalEvent, callback protocols.OutputEventCallback) error {
|
2020-12-26 09:25:15 +00:00
|
|
|
// verify if pipeline was requested
|
2020-12-30 15:44:04 +00:00
|
|
|
if r.Pipeline {
|
2021-01-01 14:06:21 +00:00
|
|
|
return r.executeTurboHTTP(reqURL, dynamicValues, callback)
|
2020-12-26 09:25:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// verify if a basic race condition was requested
|
2020-12-30 15:44:04 +00:00
|
|
|
if r.Race && r.RaceNumberRequests > 0 {
|
2021-01-01 14:06:21 +00:00
|
|
|
return r.executeRaceRequest(reqURL, dynamicValues, callback)
|
2020-12-26 09:25:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// verify if parallel elaboration was requested
|
2020-12-30 15:44:04 +00:00
|
|
|
if r.Threads > 0 {
|
2021-01-01 14:06:21 +00:00
|
|
|
return r.executeParallelHTTP(reqURL, dynamicValues, callback)
|
2020-12-26 09:25:15 +00:00
|
|
|
}
|
|
|
|
|
2020-12-30 15:44:04 +00:00
|
|
|
generator := r.newGenerator()
|
2020-12-26 09:25:15 +00:00
|
|
|
|
2020-12-28 14:32:26 +00:00
|
|
|
var requestErr error
|
|
|
|
for {
|
|
|
|
request, err := generator.Make(reqURL, dynamicValues)
|
|
|
|
if err == io.EOF {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if err != nil {
|
2020-12-30 15:44:04 +00:00
|
|
|
r.options.Progress.DecrementRequests(int64(generator.Total()))
|
2021-01-01 14:06:21 +00:00
|
|
|
return err
|
2020-12-28 14:32:26 +00:00
|
|
|
}
|
2020-12-26 09:25:15 +00:00
|
|
|
|
2021-01-01 14:06:21 +00:00
|
|
|
var gotOutput bool
|
2020-12-30 15:44:04 +00:00
|
|
|
r.options.RateLimiter.Take()
|
2021-01-01 14:06:21 +00:00
|
|
|
err = r.executeRequest(reqURL, request, dynamicValues, func(event *output.InternalWrappedEvent) {
|
2021-01-01 11:22:41 +00:00
|
|
|
// Add the extracts to the dynamic values if any.
|
2021-01-01 14:06:21 +00:00
|
|
|
if event.OperatorsResult != nil {
|
|
|
|
gotOutput = true
|
|
|
|
dynamicValues = generators.MergeMaps(dynamicValues, event.OperatorsResult.DynamicValues)
|
2021-01-01 11:22:41 +00:00
|
|
|
}
|
2021-01-01 14:06:21 +00:00
|
|
|
callback(event)
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
requestErr = multierr.Append(requestErr, err)
|
2020-12-26 09:25:15 +00:00
|
|
|
}
|
2020-12-30 15:44:04 +00:00
|
|
|
r.options.Progress.IncrementRequests()
|
2020-12-26 09:25:15 +00:00
|
|
|
|
2021-01-01 14:06:21 +00:00
|
|
|
if request.original.options.Options.StopAtFirstMatch && gotOutput {
|
2020-12-30 15:44:04 +00:00
|
|
|
r.options.Progress.DecrementRequests(int64(generator.Total()))
|
2020-12-26 09:25:15 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2021-01-01 14:06:21 +00:00
|
|
|
return requestErr
|
2020-12-26 09:25:15 +00:00
|
|
|
}
|
|
|
|
|
2020-12-28 14:32:26 +00:00
|
|
|
// executeRequest executes the actual generated request and returns error if occured
|
2021-01-01 14:06:21 +00:00
|
|
|
func (r *Request) executeRequest(reqURL string, request *generatedRequest, dynamicvalues map[string]interface{}, callback protocols.OutputEventCallback) error {
|
2020-12-26 09:25:15 +00:00
|
|
|
// Add User-Agent value randomly to the customHeaders slice if `random-agent` flag is given
|
2020-12-30 15:44:04 +00:00
|
|
|
if r.options.Options.RandomAgent {
|
2020-12-28 20:00:07 +00:00
|
|
|
builder := &strings.Builder{}
|
|
|
|
builder.WriteString("User-Agent: ")
|
|
|
|
builder.WriteString(uarand.GetRandom())
|
2021-01-12 09:44:49 +00:00
|
|
|
r.customHeaders = append(r.customHeaders, builder.String())
|
2020-12-26 09:25:15 +00:00
|
|
|
}
|
2020-12-30 15:44:04 +00:00
|
|
|
r.setCustomHeaders(request)
|
2020-12-26 09:25:15 +00:00
|
|
|
|
|
|
|
var (
|
|
|
|
resp *http.Response
|
|
|
|
err error
|
|
|
|
dumpedRequest []byte
|
|
|
|
fromcache bool
|
|
|
|
)
|
2021-01-12 11:48:08 +00:00
|
|
|
if r.options.Options.Debug || r.options.ProjectFile != nil || r.options.Options.DebugRequests {
|
2020-12-28 20:00:07 +00:00
|
|
|
dumpedRequest, err = dump(request, reqURL)
|
2020-12-26 09:25:15 +00:00
|
|
|
if err != nil {
|
2021-01-01 14:06:21 +00:00
|
|
|
return err
|
2020-12-26 09:25:15 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-12 11:48:08 +00:00
|
|
|
if r.options.Options.Debug || r.options.Options.DebugRequests {
|
2020-12-30 15:44:04 +00:00
|
|
|
gologger.Info().Msgf("[%s] Dumped HTTP request for %s\n\n", r.options.TemplateID, reqURL)
|
2020-12-26 09:25:15 +00:00
|
|
|
fmt.Fprintf(os.Stderr, "%s", string(dumpedRequest))
|
|
|
|
}
|
|
|
|
|
2021-01-11 14:29:12 +00:00
|
|
|
var formedURL string
|
2020-12-26 09:25:15 +00:00
|
|
|
timeStart := time.Now()
|
2020-12-28 14:32:26 +00:00
|
|
|
if request.original.Pipeline {
|
2021-01-11 14:29:12 +00:00
|
|
|
formedURL = request.rawRequest.FullURL
|
2020-12-28 20:00:07 +00:00
|
|
|
resp, err = request.pipelinedClient.DoRaw(request.rawRequest.Method, reqURL, request.rawRequest.Path, generators.ExpandMapValues(request.rawRequest.Headers), ioutil.NopCloser(strings.NewReader(request.rawRequest.Data)))
|
2020-12-28 14:32:26 +00:00
|
|
|
} else if request.original.Unsafe {
|
2021-01-11 14:29:12 +00:00
|
|
|
formedURL = request.rawRequest.FullURL
|
2020-12-28 20:00:07 +00:00
|
|
|
request.rawRequest.Data = strings.ReplaceAll(request.rawRequest.Data, "\n", "\r\n")
|
|
|
|
options := request.original.rawhttpClient.Options
|
2020-12-30 15:44:04 +00:00
|
|
|
options.AutomaticContentLength = !r.DisableAutoContentLength
|
|
|
|
options.AutomaticHostHeader = !r.DisableAutoHostname
|
|
|
|
options.FollowRedirects = r.Redirects
|
2020-12-28 20:00:07 +00:00
|
|
|
resp, err = request.original.rawhttpClient.DoRawWithOptions(request.rawRequest.Method, reqURL, request.rawRequest.Path, generators.ExpandMapValues(request.rawRequest.Headers), ioutil.NopCloser(strings.NewReader(request.rawRequest.Data)), options)
|
2020-12-26 09:25:15 +00:00
|
|
|
} else {
|
2021-01-11 14:29:12 +00:00
|
|
|
formedURL = request.request.URL.String()
|
2020-12-26 09:25:15 +00:00
|
|
|
// if nuclei-project is available check if the request was already sent previously
|
2020-12-30 15:44:04 +00:00
|
|
|
if r.options.ProjectFile != nil {
|
2020-12-26 09:25:15 +00:00
|
|
|
// if unavailable fail silently
|
|
|
|
fromcache = true
|
|
|
|
// nolint:bodyclose // false positive the response is generated at runtime
|
2020-12-30 15:44:04 +00:00
|
|
|
resp, err = r.options.ProjectFile.Get(dumpedRequest)
|
2020-12-26 09:25:15 +00:00
|
|
|
if err != nil {
|
|
|
|
fromcache = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if resp == nil {
|
2020-12-30 15:44:04 +00:00
|
|
|
resp, err = r.httpClient.Do(request.request)
|
2020-12-26 09:25:15 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-28 20:00:07 +00:00
|
|
|
if err != nil {
|
2021-01-11 20:35:41 +00:00
|
|
|
// rawhttp doesn't supports draining response bodies.
|
|
|
|
if resp != nil && resp.Body != nil && request.rawRequest == nil {
|
|
|
|
_, _ = io.Copy(ioutil.Discard, resp.Body)
|
2020-12-28 20:00:07 +00:00
|
|
|
resp.Body.Close()
|
|
|
|
}
|
2020-12-30 15:44:04 +00:00
|
|
|
r.options.Output.Request(r.options.TemplateID, reqURL, "http", err)
|
|
|
|
r.options.Progress.DecrementRequests(1)
|
2021-01-01 14:06:21 +00:00
|
|
|
return err
|
2020-12-28 20:00:07 +00:00
|
|
|
}
|
2021-01-11 14:29:12 +00:00
|
|
|
gologger.Verbose().Msgf("[%s] Sent HTTP request to %s", r.options.TemplateID, formedURL)
|
2020-12-30 15:44:04 +00:00
|
|
|
r.options.Output.Request(r.options.TemplateID, reqURL, "http", err)
|
2020-12-26 09:25:15 +00:00
|
|
|
|
|
|
|
duration := time.Since(timeStart)
|
|
|
|
// Dump response - Step 1 - Decompression not yet handled
|
|
|
|
var dumpedResponse []byte
|
2021-01-12 11:48:08 +00:00
|
|
|
if r.options.Options.Debug || r.options.Options.DebugResponse {
|
2020-12-26 09:25:15 +00:00
|
|
|
var dumpErr error
|
|
|
|
dumpedResponse, dumpErr = httputil.DumpResponse(resp, true)
|
|
|
|
if dumpErr != nil {
|
2021-01-01 14:06:21 +00:00
|
|
|
return errors.Wrap(dumpErr, "could not dump http response")
|
2020-12-26 09:25:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
2020-12-28 20:00:07 +00:00
|
|
|
_, _ = io.Copy(ioutil.Discard, resp.Body)
|
2020-12-26 09:25:15 +00:00
|
|
|
resp.Body.Close()
|
2021-01-01 14:06:21 +00:00
|
|
|
return errors.Wrap(err, "could not read http body")
|
2020-12-26 09:25:15 +00:00
|
|
|
}
|
|
|
|
resp.Body.Close()
|
|
|
|
|
2020-12-28 20:00:07 +00:00
|
|
|
// net/http doesn't automatically decompress the response body if an
|
|
|
|
// encoding has been specified by the user in the request so in case we have to
|
|
|
|
// manually do it.
|
2020-12-26 09:25:15 +00:00
|
|
|
dataOrig := data
|
2020-12-28 20:00:07 +00:00
|
|
|
data, err = handleDecompression(request, data)
|
2020-12-26 09:25:15 +00:00
|
|
|
if err != nil {
|
2021-01-01 14:06:21 +00:00
|
|
|
return errors.Wrap(err, "could not decompress http body")
|
2020-12-26 09:25:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Dump response - step 2 - replace gzip body with deflated one or with itself (NOP operation)
|
2021-01-12 11:48:08 +00:00
|
|
|
if r.options.Options.Debug || r.options.Options.DebugResponse {
|
2020-12-26 09:25:15 +00:00
|
|
|
dumpedResponse = bytes.ReplaceAll(dumpedResponse, dataOrig, data)
|
2021-01-11 14:29:12 +00:00
|
|
|
gologger.Info().Msgf("[%s] Dumped HTTP response for %s\n\n", r.options.TemplateID, formedURL)
|
2020-12-26 09:25:15 +00:00
|
|
|
fmt.Fprintf(os.Stderr, "%s\n", string(dumpedResponse))
|
|
|
|
}
|
|
|
|
|
|
|
|
// if nuclei-project is enabled store the response if not previously done
|
2020-12-30 15:44:04 +00:00
|
|
|
if r.options.ProjectFile != nil && !fromcache {
|
|
|
|
err := r.options.ProjectFile.Set(dumpedRequest, resp, data)
|
2020-12-26 09:25:15 +00:00
|
|
|
if err != nil {
|
2021-01-01 14:06:21 +00:00
|
|
|
return errors.Wrap(err, "could not store in project file")
|
2020-12-26 09:25:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-29 06:12:46 +00:00
|
|
|
var matchedURL string
|
|
|
|
if request.rawRequest != nil {
|
|
|
|
matchedURL = request.rawRequest.FullURL
|
|
|
|
}
|
|
|
|
if request.request != nil {
|
|
|
|
matchedURL = request.request.URL.String()
|
|
|
|
}
|
2021-01-01 14:06:21 +00:00
|
|
|
ouputEvent := r.responseToDSLMap(resp, reqURL, matchedURL, tostring.UnsafeToString(dumpedRequest), tostring.UnsafeToString(dumpedResponse), tostring.UnsafeToString(data), headersToString(resp.Header), duration, request.meta)
|
2020-12-28 20:00:07 +00:00
|
|
|
|
2021-01-01 14:06:21 +00:00
|
|
|
event := &output.InternalWrappedEvent{InternalEvent: ouputEvent}
|
2020-12-30 15:44:04 +00:00
|
|
|
if r.CompiledOperators != nil {
|
|
|
|
result, ok := r.Operators.Execute(ouputEvent, r.Match, r.Extract)
|
2020-12-28 20:00:07 +00:00
|
|
|
if !ok {
|
2021-01-01 14:06:21 +00:00
|
|
|
return nil
|
2020-12-26 09:25:15 +00:00
|
|
|
}
|
2021-01-01 14:06:21 +00:00
|
|
|
event.OperatorsResult = result
|
2021-01-01 21:09:27 +00:00
|
|
|
result.PayloadValues = request.meta
|
|
|
|
event.Results = r.makeResultEvent(event)
|
2021-01-01 14:06:21 +00:00
|
|
|
callback(event)
|
2020-12-26 09:25:15 +00:00
|
|
|
}
|
2021-01-01 14:06:21 +00:00
|
|
|
return nil
|
2020-12-28 20:00:07 +00:00
|
|
|
}
|
2020-12-26 09:25:15 +00:00
|
|
|
|
2020-12-28 20:00:07 +00:00
|
|
|
const two = 2
|
2020-12-26 09:25:15 +00:00
|
|
|
|
2020-12-28 20:00:07 +00:00
|
|
|
// setCustomHeaders sets the custom headers for generated request
|
|
|
|
func (e *Request) setCustomHeaders(r *generatedRequest) {
|
|
|
|
for _, customHeader := range e.customHeaders {
|
|
|
|
if customHeader == "" {
|
|
|
|
continue
|
|
|
|
}
|
2020-12-26 09:25:15 +00:00
|
|
|
|
2020-12-28 20:00:07 +00:00
|
|
|
// This should be pre-computed somewhere and done only once
|
|
|
|
tokens := strings.SplitN(customHeader, ":", two)
|
|
|
|
// if it's an invalid header skip it
|
|
|
|
if len(tokens) < 2 {
|
|
|
|
continue
|
2020-12-26 09:25:15 +00:00
|
|
|
}
|
|
|
|
|
2020-12-28 20:00:07 +00:00
|
|
|
headerName, headerValue := tokens[0], strings.Join(tokens[1:], "")
|
|
|
|
if r.rawRequest != nil {
|
|
|
|
r.rawRequest.Headers[headerName] = headerValue
|
|
|
|
} else {
|
|
|
|
r.request.Header.Set(strings.TrimSpace(headerName), strings.TrimSpace(headerValue))
|
|
|
|
}
|
2020-12-26 09:25:15 +00:00
|
|
|
}
|
|
|
|
}
|