Go RoundTripper and vehicles

I find it hard to understand that we need RoundTripper for Go.

https://golang.org/pkg/net/http/#RoundTripper

Explains the default Transport in Go:

 var DefaultTransport RoundTripper = &Transport{ Proxy: ProxyFromEnvironment, Dial: (&net.Dialer{ Timeout: 30 * time.Second, KeepAlive: 30 * time.Second, }).Dial, TLSHandshakeTimeout: 10 * time.Second, } 

But what's the difference between RoundTripper and this:

 transport := &http.Transport{ Proxy: http.ProxyFromEnvironment, TLSHandshakeTimeout: timeout, Dial: dialfunc, DisableKeepAlives: true, } 

My question is: RoundTripper is different from regular Transport ?

+6
source share
1 answer

I think Walker understood this in his comment on your question. From my point of view, http.Transport provides an implementation of http.RoundTripper , but you can provide your own, which is completely different if it implements RoundTrip() .

Several people have used this as a way to add speed limits (i.e. they provide an implementation that can use http.Transport under covers, but they add the ability to restrain the speed with which your program sends or receives bytes).

+5
source

Source: https://habr.com/ru/post/977628/


All Articles