mirror of
https://github.com/rakyll/hey.git
synced 2026-10-02 07:44:41 +08:00
Actually set the hey user agent in the request. (#78)
This commit is contained in:
@@ -35,6 +35,7 @@ import (
|
||||
const (
|
||||
headerRegexp = `^([\w-]+):\s*(.+)`
|
||||
authRegexp = `^(.+):([^\s].+)`
|
||||
heyUA = "hey/0.0.1"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -197,7 +198,6 @@ func main() {
|
||||
usageAndExit(err.Error())
|
||||
}
|
||||
req.ContentLength = int64(len(bodyAll))
|
||||
req.Header = header
|
||||
if username != "" || password != "" {
|
||||
req.SetBasicAuth(username, password)
|
||||
}
|
||||
@@ -207,6 +207,15 @@ func main() {
|
||||
req.Host = *hostHeader
|
||||
}
|
||||
|
||||
ua := req.UserAgent()
|
||||
if ua == "" {
|
||||
ua = heyUA
|
||||
} else {
|
||||
ua += " " + heyUA
|
||||
}
|
||||
header.Set("User-Agent", ua)
|
||||
req.Header = header
|
||||
|
||||
w := &requester.Work{
|
||||
Request: req,
|
||||
RequestBody: bodyAll,
|
||||
|
||||
@@ -30,8 +30,6 @@ import (
|
||||
"golang.org/x/net/http2"
|
||||
)
|
||||
|
||||
const heyUA = "hey/0.0.1"
|
||||
|
||||
// Max size of the buffer of result channel.
|
||||
const maxResult = 1000000
|
||||
const maxIdleConn = 500
|
||||
@@ -106,14 +104,6 @@ func (b *Work) writer() io.Writer {
|
||||
// Run makes all the requests, prints the summary. It blocks until
|
||||
// all work is done.
|
||||
func (b *Work) Run() {
|
||||
// append hey's user agent
|
||||
ua := b.Request.UserAgent()
|
||||
if ua == "" {
|
||||
ua = heyUA
|
||||
} else {
|
||||
ua += " " + heyUA
|
||||
}
|
||||
|
||||
b.results = make(chan *result, min(b.C*1000, maxResult))
|
||||
b.stopCh = make(chan struct{}, b.C)
|
||||
b.start = time.Now()
|
||||
|
||||
Reference in New Issue
Block a user