Skip to content

Commit

Permalink
Adds dr flag for discarding responses with specific string
Browse files Browse the repository at this point in the history
  • Loading branch information
GwynHannay committed Jul 5, 2020
1 parent d06f0be commit 70a2c3c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
10 changes: 10 additions & 0 deletions README.mkd
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ Usage:
Options:
-c, --concurrency <val> Set the concurrency level (defaut: 20)
-d, --delay <val> Milliseconds between requests to the same host (default: 5000)
-dr, --discresp <string> Discard responses containing specific string
-H, --header <header> Send a custom HTTP header
-r, --rawhttp Use the rawhttp library for requests (experimental)
-s, --savestatus <status> Save only responses with specific status code
Expand Down Expand Up @@ -243,6 +244,15 @@ use the `-sr` or `--saveresp` option:
▶ meg --saveresp '": "v1"' /robots.txt
```

### Discarding Certain Response Strings

Alternatively, if you don't want to save results that contained a certain string, you can
use the `-dr` or `--discresp` option:

```
▶ meg --discresp '": "v1"' /robots.txt
```

### Specifying The Method

You can specify which HTTP method to use with the `-X` or `--method` option:
Expand Down
12 changes: 10 additions & 2 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type config struct {
body string
concurrency int
delay int
discResp string
headers headerArgs
followLocation bool
method string
Expand Down Expand Up @@ -77,6 +78,11 @@ func processArgs() config {
flag.IntVar(&delay, "delay", 5000, "")
flag.IntVar(&delay, "d", 5000, "")

// discResp params
discResp := ""
flag.StringVar(&discResp, "discresp", "", "")
flag.StringVar(&discResp, "dr", "", "")

// headers params
var headers headerArgs
flag.Var(&headers, "header", "")
Expand All @@ -99,7 +105,7 @@ func processArgs() config {

// saveResp params
saveResp := ""
flag.StringVar(&saveResp, "saveResp", "", "")
flag.StringVar(&saveResp, "saveresp", "", "")
flag.StringVar(&saveResp, "sr", "", "")

// timeout param
Expand Down Expand Up @@ -151,6 +157,7 @@ func processArgs() config {
body: body,
concurrency: concurrency,
delay: delay,
discResp: discResp,
headers: headers,
followLocation: followLocation,
method: method,
Expand All @@ -177,11 +184,12 @@ func init() {
h += " -b, --body <val> Set the request body\n"
h += " -c, --concurrency <val> Set the concurrency level (default: 20)\n"
h += " -d, --delay <millis> Milliseconds between requests to the same host (default: 5000)\n"
h += " -dr, --discresp <string> Discard responses containing specific string\n"
h += " -H, --header <header> Send a custom HTTP header\n"
h += " -L, --location Follow redirects / location header\n"
h += " -r, --rawhttp Use the rawhttp library for requests (experimental)\n"
h += " -s, --savestatus <status> Save only responses with specific status code\n"
h += " -sr, --saveresp <string> Save only responses containing specific string\n"
h += " -sr, --saveresp <string> Save only responses containing specific string\n"
h += " -t, --timeout <millis> Set the HTTP timeout (default: 10000)\n"
h += " -v, --verbose Verbose mode\n"
h += " -X, --method <method> HTTP method (default: GET)\n\n"
Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ func main() {
continue
}

if len(c.discResp) > 0 && (strings.Contains(strings.Join(res.headers, ""), c.discResp) || (strings.Contains(string(res.body), c.discResp))) {
continue
}

if res.err != nil {
fmt.Fprintf(os.Stderr, "request failed: %s\n", res.err)
continue
Expand Down

0 comments on commit 70a2c3c

Please sign in to comment.