diff --git a/README.md b/README.md index 66c4299..081dd61 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,8 @@ Usage: httping [options] Whether to not count requests that did not reuse a connection towards the final statistics -timeout uint Request timeout in milliseconds (default 5000) + -user-agent string + Change the User-Agent header (default "httping (https://github.com/GitRowin/httping)") ``` Example: `httping -count 10 -disable-compression -timeout 1000 https://example.com/` diff --git a/main.go b/main.go index 628b1c1..42d107b 100644 --- a/main.go +++ b/main.go @@ -26,6 +26,7 @@ var ( disableCompression bool disableHttp2 bool noNewConnCount bool + userAgent string ) func init() { @@ -36,6 +37,7 @@ func init() { flag.BoolVar(&disableCompression, "disable-compression", false, "Whether to disable compression") flag.BoolVar(&disableHttp2, "disable-h2", false, "Whether to disable HTTP/2") flag.BoolVar(&noNewConnCount, "no-new-conn-count", false, "Whether to not count requests that did not reuse a connection towards the final statistics") + flag.StringVar(&userAgent, "user-agent", "httping (https://github.com/GitRowin/httping)", "Change the User-Agent header") } 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 // Make a new GET request with the client trace req, err := http.NewRequestWithContext(httptrace.WithClientTrace(ctx, trace), "GET", targetUrl, nil) + req.Header.Set("User-Agent", userAgent) + // Send the request res, err := client.Do(req)