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
859 stars 164 forks source link

Support defining useragent in connect request #125

Closed 043674543 closed 4 months ago

043674543 commented 4 months ago

The CONNECT request contains a useragent which we can set in the connect.go

(not a golang coder typically so please feel free to raise any issues this may have)

bogdanfinn commented 4 months ago

@043674543 thank you for your contribution. what do you think about adjusting the changeset a bit and extend the functionality.

I think of setting the whole default header map via config option (default should be make(http.Header)). So the option could be named:

func WithConnectHeaders(headers http.Header) HttpClientOption {
    return func(config *httpClientConfig) {
        config.connectHeaders = headers
    }
}

And then passing this option to the newConnectDialer and set it directly where the connectDialer is instantiated:

dialer := &connectDialer{
        logger:            logger,
        ProxyUrl:          *proxyUrl,
        Dialer:            _dialer,
        Timeout:           timeout,
        DefaultHeader:     make(http.Header), // set it here directly
        EnableH2ConnReuse: true,
}

This would give the user the flexibility to add more than just the user-agent header.

bogdanfinn commented 4 months ago

@043674543 covered now in https://github.com/bogdanfinn/tls-client/releases/tag/v1.7.7 thank you very much.