bogdanfinn / tls-client

net/http.Client like HTTP Client with options to select specific client TLS Fingerprints to use for requests.
BSD 4-Clause "Original" or "Old" License
667 stars 133 forks source link

Optional bandwidth tracker #114

Closed MashinaMashina closed 1 month ago

MashinaMashina commented 1 month ago

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

tls_client.WithBandwidthTracker()
MashinaMashina commented 1 month ago

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 commented 1 month ago

@MashinaMashina thank you for your contribution