Skip to content

Commit

Permalink
Add ability to ignore headers when diffing
Browse files Browse the repository at this point in the history
   -ignore

Comma-separated list of headers to ignore
  • Loading branch information
jgrahamc committed Mar 24, 2015
1 parent 2b1c89e commit f7d7815
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/httpdiff/httpdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"
"net/http"
"os"
"strings"
"sync"
)

Expand Down Expand Up @@ -56,12 +57,24 @@ func do(method, host, uri string) (*http.Response, []byte, error) {
func main() {
method := flag.String("method", "GET", "Sets the HTTP method")
host := flag.String("host", "", "Sets the Host header")
ignore := flag.String("ignore", "",
"Comma-separated list of headers to ignore")
flag.Parse()
if len(flag.Args()) != 2 {
fmt.Printf("Must specify two URIs to test\n")
return
}

exclude := make(map[string]bool)

if *ignore != "" {
h := strings.Split(*ignore, ",")

for i := 0; i < len(h); i++ {
exclude[http.CanonicalHeaderKey(h[i])] = true
}
}

var wg sync.WaitGroup

fmt.Printf("Doing %s %s\n", *method, vs(flag.Arg(0), flag.Arg(1)))
Expand Down Expand Up @@ -98,6 +111,9 @@ func main() {
}

for h := range resp[0].Header {
if exclude[h] {
continue
}
h2 := resp[1].Header[h]
if h2 != nil {
if len(resp[0].Header[h]) != len(resp[1].Header[h]) {
Expand All @@ -118,6 +134,9 @@ func main() {


for h := range resp[0].Header {
if exclude[h] {
continue
}
h2 := resp[1].Header[h]
if h2 == nil {
fmt.Printf("%s has %s header (%s does not)\n", on(0, flag.Arg(0)),
Expand All @@ -126,6 +145,9 @@ func main() {
}

for h := range resp[1].Header {
if exclude[h] {
continue
}
h2 := resp[0].Header[h]
if h2 == nil {
fmt.Printf("%s has %s header (%s does not)\n", on(1, flag.Arg(1)),
Expand Down

0 comments on commit f7d7815

Please sign in to comment.