golang1.18 Transport源码
时间: 2024-01-02 17:05:02 浏览: 72
以下是 Go 1.18 中 `http.Transport` 的源码注释:
```go
// Transport is an implementation of RoundTripper that supports HTTP, HTTPS, and HTTP proxies
// (with or without proxy authentication). It implements the http.RoundTripper interface.
//
// By default, Transport caches connections for future re-use. This may leave many open
// connections when accessing many hosts. This behavior can be managed using Transport's
// CloseIdleConnections method and the MaxIdleConnsPerHost and DisableKeepAlives fields.
//
// Transports should be reused instead of created as needed. Transports are safe for
// concurrent use by multiple goroutines.
type Transport struct {
// Proxy specifies a function to return a proxy for a given Request.
// If the function returns a non-nil error, the request is aborted
// with the provided error.
//
// If Proxy is nil or returns a nil *URL, no proxy is used.
Proxy func(*Request) (*url.URL, error)
// DialContext specifies the dial function for creating unencrypted TCP connections.
// If DialContext is nil (and the deprecated Dial below is also nil),
// then the transport dials using package net.
DialContext func(ctx context.Context, network, addr string) (net.Conn, error)
// ...
// 其他字段和方法省略,具体可以参考 Go 的源码文档
// ...
}
```
你可以通过访问 [Go 1.18 的源码仓库](https://github.com/golang/go/tree/go1.18/src/net/http) 查看完整的源代码实现。
阅读全文