Skip to content

Commit

Permalink
adding response time to DSL
Browse files Browse the repository at this point in the history
  • Loading branch information
Mzack9999 committed Sep 29, 2020
1 parent fee5099 commit fd1d249
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 3 additions & 1 deletion v2/pkg/executer/executer_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ func (e *HTTPExecuter) handleHTTP(reqURL string, request *requests.HTTPRequest,
fmt.Fprintf(os.Stderr, "%s", string(dumpedRequest))
}

timeStart := time.Now()
resp, err := e.httpClient.Do(req)
duration := time.Since(timeStart)

if err != nil {
if resp != nil {
Expand Down Expand Up @@ -223,7 +225,7 @@ func (e *HTTPExecuter) handleHTTP(reqURL string, request *requests.HTTPRequest,

for _, matcher := range e.bulkHTTPRequest.Matchers {
// Check if the matcher matched
if !matcher.Match(resp, body, headers) {
if !matcher.Match(resp, body, headers, duration) {
// If the condition is AND we haven't matched, try next request.
if matcherCondition == matchers.ANDCondition {
return nil
Expand Down
5 changes: 3 additions & 2 deletions v2/pkg/matchers/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"encoding/hex"
"net/http"
"strings"
"time"

"github.com/miekg/dns"
)

// Match matches a http response again a given matcher
func (m *Matcher) Match(resp *http.Response, body, headers string) bool {
func (m *Matcher) Match(resp *http.Response, body, headers string, duration time.Duration) bool {
switch m.matcherType {
case StatusMatcher:
return m.isNegative(m.matchStatusCode(resp.StatusCode))
Expand Down Expand Up @@ -44,7 +45,7 @@ func (m *Matcher) Match(resp *http.Response, body, headers string) bool {
}
case DSLMatcher:
// Match complex query
return m.isNegative(m.matchDSL(httpToMap(resp, body, headers)))
return m.isNegative(m.matchDSL(httpToMap(resp, body, headers, duration)))
}

return false
Expand Down
6 changes: 5 additions & 1 deletion v2/pkg/matchers/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
"net/http"
"net/http/httputil"
"strings"
"time"

"github.com/miekg/dns"
)

func httpToMap(resp *http.Response, body, headers string) (m map[string]interface{}) {
func httpToMap(resp *http.Response, body, headers string, duration time.Duration) (m map[string]interface{}) {
m = make(map[string]interface{})

m["content_length"] = resp.ContentLength
Expand All @@ -27,6 +28,9 @@ func httpToMap(resp *http.Response, body, headers string) (m map[string]interfac
m["raw"] = string(r)
}

// should be used as int64 within DSL syntax
m["duration"] = duration

return m
}

Expand Down

0 comments on commit fd1d249

Please sign in to comment.