Skip to content

Commit

Permalink
-r print response
Browse files Browse the repository at this point in the history
  • Loading branch information
Mengchao.Lv1 authored and Mengchao.Lv1 committed Jan 29, 2024
1 parent e9053ed commit 390e304
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions hey.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ var (
z = flag.Duration("z", 0, "")
p = flag.Duration("p", time.Second, "")

r = flag.Bool("r", false, "")

h2 = flag.Bool("h2", false, "")
cpus = flag.Int("cpus", runtime.GOMAXPROCS(-1), "")

Expand Down Expand Up @@ -94,6 +96,7 @@ Options:
-x HTTP Proxy address as host:port.
-h2 Enable HTTP/2.
-p Preview results interval. Default is 1s.
-r Print http response
-host HTTP Host header.
Expand Down Expand Up @@ -124,6 +127,7 @@ func main() {
q := *q
dur := *z
report := *p
debug := *r

if dur > 0 {
num = math.MaxInt32
Expand Down Expand Up @@ -238,6 +242,7 @@ func main() {
ProxyAddr: proxyURL,
Output: *output,
ReportPreview: report,
Debug: debug,
}
w.Init()

Expand Down
10 changes: 9 additions & 1 deletion requester/requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/gosuri/uilive"
"io"
"io/ioutil"
"log"
"net/http"
"net/http/httptrace"
"net/url"
Expand Down Expand Up @@ -99,6 +100,8 @@ type Work struct {
stopCh chan struct{}
start time.Duration

Debug bool

report *report
// Preview output the current result in advance
ReportPreview time.Duration
Expand Down Expand Up @@ -223,7 +226,12 @@ func (b *Work) makeRequest(c *http.Client) {
if err == nil {
size = resp.ContentLength
code = resp.StatusCode
io.Copy(ioutil.Discard, resp.Body)
if b.Debug {
res, _ := io.ReadAll(resp.Body)
log.Printf("res %s", string(res))
} else {
_, _ = io.Copy(io.Discard, resp.Body)
}
resp.Body.Close()
}
t := now()
Expand Down

0 comments on commit 390e304

Please sign in to comment.