Skip to content

Commit

Permalink
Adds experimental nopath option
Browse files Browse the repository at this point in the history
  • Loading branch information
tomnomnom committed Mar 27, 2018
1 parent c189b3c commit 275c5ed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
7 changes: 7 additions & 0 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type config struct {
delay int
headers headerArgs
followLocation bool
noPath bool
method string
saveStatus int
timeout int
Expand Down Expand Up @@ -57,6 +58,10 @@ func processArgs() config {
flag.BoolVar(&followLocation, "location", false, "")
flag.BoolVar(&followLocation, "L", false, "")

// no path part
noPath := false
flag.BoolVar(&noPath, "nopath", false, "")

// method param
method := "GET"
flag.StringVar(&method, "method", "GET", "")
Expand Down Expand Up @@ -113,6 +118,7 @@ func processArgs() config {
delay: delay,
headers: headers,
followLocation: followLocation,
noPath: noPath,
method: method,
saveStatus: saveStatus,
timeout: timeout,
Expand All @@ -136,6 +142,7 @@ func init() {
h += " -d, --delay <millis> Milliseconds between requests to the same host (defaut: 5000)\n"
h += " -H, --header <header> Send a custom HTTP header\n"
h += " -L, --location Follow redirects / location header\n"
h += " --nopath Treat the hosts file as complete URLs\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 += " -t, --timeout <millis> Set the HTTP timeout (default: 10000)\n"
Expand Down
16 changes: 11 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ func main() {
// get the config struct
c := processArgs()

// read the paths file
paths, err := readLinesOrLiteral(c.paths, defaultPathsFile)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to open paths file: %s\n", err)
os.Exit(1)
// read the paths file; unless the nopath option is set
var paths []string
var err error
if c.noPath {
paths = []string{""}
} else {
paths, err = readLinesOrLiteral(c.paths, defaultPathsFile)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to open paths file: %s\n", err)
os.Exit(1)
}
}

// read the hosts file
Expand Down

0 comments on commit 275c5ed

Please sign in to comment.