Kethsar / ytarchive

Garbage Youtube livestream downloader
MIT License
1.15k stars 93 forks source link

Clone http.DefaultTransport rather than making our own. #83

Closed Hakkin closed 2 years ago

Hakkin commented 2 years ago

This lets us inherit the useful/sane defaults of the default transport. The most obvious benefit it inherits is supporting HTTP(S)_PROXY env variables from the http.ProxyFromEnvironment function. This lets you set http(s)/socks5 proxies for the program to use. This could be manually set on the Proxy field of Transport, but there's really no reason not to just clone the default transport as a base. TLSHandshakeTimeout is already set to 10 seconds on the default transport so I omitted setting that, ResponseHeaderTimeout isn't set by default though so I kept that around.

Kethsar commented 2 years ago

Neat, I never even considered that. Though I also completely missed there being a clone() function for http.Transport. I think I even remember trying to figure out how to use the default transport but couldn't figure it out. Forgot that casting is a thing.