Skip to content

Commit 85ff2d4

Browse files
committed
Add a flag to change the User-Agent header
1 parent 8769923 commit 85ff2d4

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ Usage: httping [options] <url>
3939
Whether to not count requests that did not reuse a connection towards the final statistics
4040
-timeout uint
4141
Request timeout in milliseconds (default 5000)
42+
-user-agent string
43+
Change the User-Agent header (default "httping (https://github.com/GitRowin/httping)")
4244
```
4345

4446
Example: `httping -count 10 -disable-compression -timeout 1000 https://example.com/`

main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var (
2626
disableCompression bool
2727
disableHttp2 bool
2828
noNewConnCount bool
29+
userAgent string
2930
)
3031

3132
func init() {
@@ -36,6 +37,7 @@ func init() {
3637
flag.BoolVar(&disableCompression, "disable-compression", false, "Whether to disable compression")
3738
flag.BoolVar(&disableHttp2, "disable-h2", false, "Whether to disable HTTP/2")
3839
flag.BoolVar(&noNewConnCount, "no-new-conn-count", false, "Whether to not count requests that did not reuse a connection towards the final statistics")
40+
flag.StringVar(&userAgent, "user-agent", "httping (https://github.com/GitRowin/httping)", "Change the User-Agent header")
3941
}
4042

4143
type TLSNextProtoMap = map[string]func(authority string, c *tls.Conn) http.RoundTripper
@@ -239,6 +241,8 @@ func sendRequest(client *http.Client, ctx context.Context, targetUrl string) (*S
239241
// Make a new GET request with the client trace
240242
req, err := http.NewRequestWithContext(httptrace.WithClientTrace(ctx, trace), "GET", targetUrl, nil)
241243

244+
req.Header.Set("User-Agent", userAgent)
245+
242246
// Send the request
243247
res, err := client.Do(req)
244248

0 commit comments

Comments
 (0)