Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional bandwidth tracker #114

Merged
merged 5 commits into from
May 13, 2024
Merged

Conversation

MashinaMashina
Copy link
Contributor

@MashinaMashina MashinaMashina commented May 13, 2024

Not everyone needs a tracker. If you needs, enable using option:

tls_client.WithBandwidthTracker()

client_options.go Outdated Show resolved Hide resolved
@MashinaMashina
Copy link
Contributor Author

MashinaMashina commented May 13, 2024

ctx in TrackConnection method allows add your logic in custom implementation. Example:

req, err := http.NewRequestWithContext(context.WithValue(context.Background(), "do_not_track", "1"), http.MethodGet, "https://www.topps.com/", nil)
...
func (bt *Tracker) TrackConnection(ctx context.Context, conn net.Conn) net.Conn {
	if ctx.Value("do_not_track") != nil {
		return conn
	}

	return newTrackedConn(conn, bt)
}

(In example, I need to measure traffic by individual routes. With ctx I store route, and in my tracker implementation i will write to different trackers)

@bogdanfinn bogdanfinn merged commit 077a497 into bogdanfinn:master May 13, 2024
@bogdanfinn
Copy link
Owner

@MashinaMashina thank you for your contribution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants