Hi all, Can someone explain, what is http roundtripper?
Thanks
评论:
pierrrre:
zero_coding:http://golang.org/pkg/net/http/#RoundTripper It's like a low level http client.
jewishobo:what can I do with a roundtripper?
comrade_donkey:Here is a long video about using the roundtripper interface to make an HTTP/2 client. https://www.youtube.com/watch?v=yG-UaBJXZ80
drvd:Take a look at http.Transport
kodemizer:It is an interface, so all you can do is invoke its single method RoundTrip and I think the documentation is pretty clear.
For http clients, it's behaviour can be configured using different RoundTripper implementations. By default, an http client will use an appropriately configured Transport struct (which satisfies a RoundTripper).
By default, the Transport struct is configured to re-use network connections from a pool, timeout after a certain amount of time, use a certain proxy service etc.
If you wanted to modify the behavior of your http client you have two options:
Use the pre-existing Transport struct and configure appropriately.
Write your very own implementation. As long as it satisfies RoupTripper, it can be used. You could do something creative like implement http over SSH, or some other crazy madness.