Skip to content

Commit

Permalink
Merge pull request #18 from agile6v/master
Browse files Browse the repository at this point in the history
add support for request body (-body option)
  • Loading branch information
jgrahamc committed Jun 7, 2016
2 parents d923ca3 + d7d5d94 commit 97865fa
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions httpdiff.go
Expand Up @@ -59,8 +59,15 @@ func vsi(a, b int, f string, v ...interface{}) bool {
// do an HTTP request to a server and returns the response object and the
// complete response body. There's no need to close the response body as this
// will have been done.
func do(method, host, ua, uri string) (*http.Response, []byte, error) {
req, err := http.NewRequest(method, uri, nil)
func do(method, req_body, host, ua, uri string) (*http.Response, []byte, error) {
var err error
var req *http.Request
if strings.EqualFold("POST", method) || strings.EqualFold("PUT", method) {
req, err = http.NewRequest(method, uri, strings.NewReader(req_body))
} else {
req, err = http.NewRequest(method, uri, nil)
}

if err != nil {
return nil, nil, err
}
Expand All @@ -85,6 +92,7 @@ func do(method, host, ua, uri string) (*http.Response, []byte, error) {

func main() {
method := flag.String("method", "GET", "Sets the HTTP method")
req_body := flag.String("body", "", "Sets body data to send server")
host := flag.String("host", "",
"Sets the Host header sent with both requests")
ignore := flag.String("ignore", "",
Expand Down Expand Up @@ -137,7 +145,7 @@ func main() {
for i := 0; i < 2; i++ {
wg.Add(1)
go func(i int) {
resp[i], body[i], err[i] = do(*method, *host, *ua, flag.Arg(i))
resp[i], body[i], err[i] = do(*method, *req_body, *host, *ua, flag.Arg(i))
wg.Done()
}(i)
}
Expand Down

0 comments on commit 97865fa

Please sign in to comment.