Skip to content

Commit

Permalink
Add a flag to change the User-Agent header
Browse files Browse the repository at this point in the history
  • Loading branch information
GitRowin committed Aug 19, 2023
1 parent 8769923 commit 85ff2d4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Usage: httping [options] <url>
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/`
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var (
disableCompression bool
disableHttp2 bool
noNewConnCount bool
userAgent string
)

func init() {
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 85ff2d4

Please sign in to comment.