Skip to content

Commit

Permalink
Adds --no-headers option
Browse files Browse the repository at this point in the history
  • Loading branch information
tomnomnom committed Sep 25, 2018
1 parent 789c6dc commit f592548
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
12 changes: 9 additions & 3 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ type config struct {
timeout int
verbose bool

paths string
hosts string
output string
paths string
hosts string
output string
noHeaders bool

requester requester
}
Expand Down Expand Up @@ -99,6 +100,10 @@ func processArgs() config {
flag.BoolVar(&rawHTTP, "rawhttp", false, "")
flag.BoolVar(&rawHTTP, "r", false, "")

// no headers
noHeaders := false
flag.BoolVar(&noHeaders, "no-headers", false, "")

// verbose param
verbose := false
flag.BoolVar(&verbose, "verbose", false, "")
Expand Down Expand Up @@ -143,6 +148,7 @@ func processArgs() config {
paths: paths,
hosts: hosts,
output: output,
noHeaders: noHeaders,
}
}

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func main() {
continue
}

path, err := res.save(c.output)
path, err := res.save(c.output, c.noHeaders)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to save file: %s\n", err)
}
Expand Down
14 changes: 13 additions & 1 deletion response.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,22 @@ func (r response) String() string {
return b.String()
}

func (r response) StringNoHeaders() string {
b := &bytes.Buffer{}

b.Write(r.body)

return b.String()
}

// save write a request and response output to disk
func (r response) save(pathPrefix string) (string, error) {
func (r response) save(pathPrefix string, noHeaders bool) (string, error) {

content := []byte(r.String())
if noHeaders {
content = []byte(r.StringNoHeaders())
}

checksum := sha1.Sum(content)
parts := []string{pathPrefix}

Expand Down

0 comments on commit f592548

Please sign in to comment.