go/src/net/http/transport.go

var DefaultTransport

const DefaultMaxIdleConnsPerHost

type Transport

func (t *Transport) writeBufferSize() int {}

func (t *Transport) readBufferSize() int {}

// Clone returns a deep copy of t's exported fields.
func (t *Transport) Clone() *Transport {}

type h2Transport

func (t *Transport) hasCustomTLSDialer() bool {}

var http2client

// onceSetNextProtoDefaults initializes TLSNextProto.
// It must be called via t.nextProtoOnce.Do.
func (t *Transport) onceSetNextProtoDefaults() {}

// ProxyFromEnvironment returns the URL of the proxy to use for a
// given request, as indicated by the environment variables
// HTTP_PROXY, HTTPS_PROXY and NO_PROXY (or the lowercase versions
// thereof). Requests use the proxy from the environment variable
// matching their scheme, unless excluded by NO_PROXY.
//
// The environment values may be either a complete URL or a
// "host[:port]", in which case the "http" scheme is assumed.
// An error is returned if the value is a different form.
//
// A nil URL and nil error are returned if no proxy is defined in the
// environment, or a proxy should not be used for the given request,
// as defined by NO_PROXY.
//
// As a special case, if req.URL.Host is "localhost" (with or without
// a port number), then a nil URL and nil error will be returned.
func ProxyFromEnvironment(req *Request) (*url.URL, error) {}

// ProxyURL returns a proxy function (for use in a [Transport])
// that always returns the same URL.
func ProxyURL(fixedURL *url.URL) func(*Request) (*url.URL, error) {}

type transportRequest

func (tr *transportRequest) extraHeaders() Header {}

func (tr *transportRequest) setError(err error) {}

// useRegisteredProtocol reports whether an alternate protocol (as registered
// with Transport.RegisterProtocol) should be respected for this request.
func (t *Transport) useRegisteredProtocol(req *Request) bool {}

// alternateRoundTripper returns the alternate RoundTripper to use
// for this request if the Request's URL scheme requires one,
// or nil for the normal case of using the Transport.
func (t *Transport) alternateRoundTripper(req *Request) RoundTripper {}

func validateHeaders(hdrs Header) string {}

// roundTrip implements a RoundTripper over HTTP.
func (t *Transport) roundTrip(req *Request) (_ *Response, err error) {}

func awaitLegacyCancel(ctx context.Context, cancel context.CancelCauseFunc, req *Request) {}

var errCannotRewind

type readTrackingBody

func (r *readTrackingBody) Read(data []byte) (int, error) {}

func (r *readTrackingBody) Close() error {}

// setupRewindBody returns a new request with a custom body wrapper
// that can report whether the body needs rewinding.
// This lets rewindBody avoid an error result when the request
// does not have GetBody but the body hasn't been read at all yet.
func setupRewindBody(req *Request) *Request {}

// rewindBody returns a new request with the body rewound.
// It returns req unmodified if the body does not need rewinding.
// rewindBody takes care of closing req.Body when appropriate
// (in all cases except when rewindBody returns req unmodified).
func rewindBody(req *Request) (rewound *Request, err error) {}

// shouldRetryRequest reports whether we should retry sending a failed
// HTTP request on a new connection. The non-nil input error is the
// error from roundTrip.
func (pc *persistConn) shouldRetryRequest(req *Request, err error) bool {}

var ErrSkipAltProtocol

// RegisterProtocol registers a new protocol with scheme.
// The [Transport] will pass requests using the given scheme to rt.
// It is rt's responsibility to simulate HTTP request semantics.
//
// RegisterProtocol can be used by other packages to provide
// implementations of protocol schemes like "ftp" or "file".
//
// If rt.RoundTrip returns [ErrSkipAltProtocol], the Transport will
// handle the [Transport.RoundTrip] itself for that one request, as if the
// protocol were not registered.
func (t *Transport) RegisterProtocol(scheme string, rt RoundTripper) {}

// CloseIdleConnections closes any connections which were previously
// connected from previous requests but are now sitting idle in
// a "keep-alive" state. It does not interrupt any connections currently
// in use.
func (t *Transport) CloseIdleConnections() {}

// prepareTransportCancel sets up state to convert Transport.CancelRequest into context cancelation.
func (t *Transport) prepareTransportCancel(req *Request, origCancel context.CancelCauseFunc) context.CancelCauseFunc {}

// CancelRequest cancels an in-flight request by closing its connection.
// CancelRequest should only be called after [Transport.RoundTrip] has returned.
//
// Deprecated: Use [Request.WithContext] to create a request with a
// cancelable context instead. CancelRequest cannot cancel HTTP/2
// requests. This may become a no-op in a future release of Go.
func (t *Transport) CancelRequest(req *Request) {}

var envProxyOnce

var envProxyFuncValue

// envProxyFunc returns a function that reads the
// environment variable to determine the proxy address.
func envProxyFunc() func(*url.URL) (*url.URL, error) {}

// resetProxyConfig is used by tests.
func resetProxyConfig() {}

func (t *Transport) connectMethodForRequest(treq *transportRequest) (cm connectMethod, err error) {}

// proxyAuth returns the Proxy-Authorization header to set
// on requests, if applicable.
func (cm *connectMethod) proxyAuth() string {}

var errKeepAlivesDisabled

var errConnBroken

var errCloseIdle

var errTooManyIdle

var errTooManyIdleHost

var errCloseIdleConns

var errReadLoopExiting

var errIdleConnTimeout

var errServerClosedIdle

type transportReadFromServerError

func (e transportReadFromServerError) Unwrap() error {}

func (e transportReadFromServerError) Error() string {}

func (t *Transport) putOrCloseIdleConn(pconn *persistConn) {}

func (t *Transport) maxIdleConnsPerHost() int {}

// tryPutIdleConn adds pconn to the list of idle persistent connections awaiting
// a new request.
// If pconn is no longer needed or not in a good state, tryPutIdleConn returns
// an error explaining why it wasn't registered.
// tryPutIdleConn does not close pconn. Use putOrCloseIdleConn instead for that.
func (t *Transport) tryPutIdleConn(pconn *persistConn) error {}

// queueForIdleConn queues w to receive the next idle connection for w.cm.
// As an optimization hint to the caller, queueForIdleConn reports whether
// it successfully delivered an already-idle connection.
func (t *Transport) queueForIdleConn(w *wantConn) (delivered bool) {}

// removeIdleConn marks pconn as dead.
func (t *Transport) removeIdleConn(pconn *persistConn) bool {}

// t.idleMu must be held.
func (t *Transport) removeIdleConnLocked(pconn *persistConn) bool {}

var zeroDialer

func (t *Transport) dial(ctx context.Context, network, addr string) (net.Conn, error) {}

type wantConn

type connOrError

// waiting reports whether w is still waiting for an answer (connection or error).
func (w *wantConn) waiting() bool {}

// getCtxForDial returns context for dial or nil if connection was delivered or canceled.
func (w *wantConn) getCtxForDial() context.Context {}

// tryDeliver attempts to deliver pc, err to w and reports whether it succeeded.
func (w *wantConn) tryDeliver(pc *persistConn, err error, idleAt time.Time) bool {}

// cancel marks w as no longer wanting a result (for example, due to cancellation).
// If a connection has been delivered already, cancel returns it with t.putOrCloseIdleConn.
func (w *wantConn) cancel(t *Transport, err error) {}

type wantConnQueue

// len returns the number of items in the queue.
func (q *wantConnQueue) len() int {}

// pushBack adds w to the back of the queue.
func (q *wantConnQueue) pushBack(w *wantConn) {}

// popFront removes and returns the wantConn at the front of the queue.
func (q *wantConnQueue) popFront() *wantConn {}

// peekFront returns the wantConn at the front of the queue without removing it.
func (q *wantConnQueue) peekFront() *wantConn {}

// cleanFrontNotWaiting pops any wantConns that are no longer waiting from the head of the
// queue, reporting whether any were popped.
func (q *wantConnQueue) cleanFrontNotWaiting() (cleaned bool) {}

// cleanFrontCanceled pops any wantConns with canceled dials from the head of the queue.
func (q *wantConnQueue) cleanFrontCanceled() {}

// all iterates over all wantConns in the queue.
// The caller must not modify the queue while iterating.
func (q *wantConnQueue) all(f func(*wantConn)) {}

func (t *Transport) customDialTLS(ctx context.Context, network, addr string) (conn net.Conn, err error) {}

// getConn dials and creates a new persistConn to the target as
// specified in the connectMethod. This includes doing a proxy CONNECT
// and/or setting up TLS.  If this doesn't return an error, the persistConn
// is ready to write requests to.
func (t *Transport) getConn(treq *transportRequest, cm connectMethod) (_ *persistConn, err error) {}

// queueForDial queues w to wait for permission to begin dialing.
// Once w receives permission to dial, it will do so in a separate goroutine.
func (t *Transport) queueForDial(w *wantConn) {}

// startDialConnFor calls dialConn in a new goroutine.
// t.connsPerHostMu must be held.
func (t *Transport) startDialConnForLocked(w *wantConn) {}

// dialConnFor dials on behalf of w and delivers the result to w.
// dialConnFor has received permission to dial w.cm and is counted in t.connCount[w.cm.key()].
// If the dial is canceled or unsuccessful, dialConnFor decrements t.connCount[w.cm.key()].
func (t *Transport) dialConnFor(w *wantConn) {}

// decConnsPerHost decrements the per-host connection count for key,
// which may in turn give a different waiting goroutine permission to dial.
func (t *Transport) decConnsPerHost(key connectMethodKey) {}

// Add TLS to a persistent connection, i.e. negotiate a TLS session. If pconn is already a TLS
// tunnel, this function establishes a nested TLS session inside the encrypted channel.
// The remote endpoint's name may be overridden by TLSClientConfig.ServerName.
func (pconn *persistConn) addTLS(ctx context.Context, name string, trace *httptrace.ClientTrace) error {}

type erringRoundTripper

var testHookProxyConnectTimeout

func (t *Transport) dialConn(ctx context.Context, cm connectMethod) (pconn *persistConn, err error) {}

type persistConnWriter

func (w persistConnWriter) Write(p []byte) (n int, err error) {}

// ReadFrom exposes persistConnWriter's underlying Conn to io.Copy and if
// the Conn implements io.ReaderFrom, it can take advantage of optimizations
// such as sendfile.
func (w persistConnWriter) ReadFrom(r io.Reader) (n int64, err error) {}

var _

type connectMethod

func (cm *connectMethod) key() connectMethodKey {}

// scheme returns the first hop scheme: http, https, or socks5
func (cm *connectMethod) scheme() string {}

// addr returns the first hop "host:port" to which we need to TCP connect.
func (cm *connectMethod) addr() string {}

// tlsHost returns the host name to match against the peer's
// TLS certificate.
func (cm *connectMethod) tlsHost() string {}

type connectMethodKey

func (k connectMethodKey) String() string {}

type persistConn

func (pc *persistConn) maxHeaderResponseSize() int64 {}

func (pc *persistConn) Read(p []byte) (n int, err error) {}

// isBroken reports whether this connection is in a known broken state.
func (pc *persistConn) isBroken() bool {}

// canceled returns non-nil if the connection was closed due to
// CancelRequest or due to context cancellation.
func (pc *persistConn) canceled() error {}

// isReused reports whether this connection has been used before.
func (pc *persistConn) isReused() bool {}

func (pc *persistConn) cancelRequest(err error) {}

// closeConnIfStillIdle closes the connection if it's still sitting idle.
// This is what's called by the persistConn's idleTimer, and is run in its
// own goroutine.
func (pc *persistConn) closeConnIfStillIdle() {}

// mapRoundTripError returns the appropriate error value for
// persistConn.roundTrip.
//
// The provided err is the first error that (*persistConn).roundTrip
// happened to receive from its select statement.
//
// The startBytesWritten value should be the value of pc.nwrite before the roundTrip
// started writing the request.
func (pc *persistConn) mapRoundTripError(req *transportRequest, startBytesWritten int64, err error) error {}

var errCallerOwnsConn

func (pc *persistConn) readLoop() {}

func (pc *persistConn) readLoopPeekFailLocked(peekErr error) {}

// is408Message reports whether buf has the prefix of an
// HTTP 408 Request Timeout response.
// See golang.org/issue/32310.
func is408Message(buf []byte) bool {}

// readResponse reads an HTTP response (or two, in the case of "Expect:
// 100-continue") from the server. It returns the final non-100 one.
// trace is optional.
func (pc *persistConn) readResponse(rc requestAndChan, trace *httptrace.ClientTrace) (resp *Response, err error) {}

// waitForContinue returns the function to block until
// any response, timeout or connection close. After any of them,
// the function returns a bool which indicates if the body should be sent.
func (pc *persistConn) waitForContinue(continueCh <-chan struct{}

func newReadWriteCloserBody(br *bufio.Reader, rwc io.ReadWriteCloser) io.ReadWriteCloser {}

type readWriteCloserBody

func (b *readWriteCloserBody) Read(p []byte) (n int, err error) {}

type nothingWrittenError

func (nwe nothingWrittenError) Unwrap() error {}

func (pc *persistConn) writeLoop() {}

var maxWriteWaitBeforeConnReuse

// wroteRequest is a check before recycling a connection that the previous write
// (from writeLoop above) happened and was successful.
func (pc *persistConn) wroteRequest() bool {}

type responseAndError

type requestAndChan

type writeRequest

type timeoutError

func (e *timeoutError) Error() string     {}

func (e *timeoutError) Timeout() bool     {}

func (e *timeoutError) Temporary() bool   {}

func (e *timeoutError) Is(err error) bool {}

var errTimeout

var errRequestCanceled

var errRequestCanceledConn

var errRequestDone

func nop() {}

var testHookEnterRoundTrip

var testHookWaitResLoop

var testHookRoundTripRetried

var testHookPrePendingDial

var testHookPostPendingDial

var testHookMu

var testHookReadLoopBeforeNextRead

func (pc *persistConn) roundTrip(req *transportRequest) (resp *Response, err error) {}

type tLogKey

func (tr *transportRequest) logf(format string, args ...any) {}

// markReused marks this connection as having been successfully used for a
// request and response.
func (pc *persistConn) markReused() {}

// close closes the underlying TCP connection and closes
// the pc.closech channel.
//
// The provided err is only for testing and debugging; in normal
// circumstances it should never be seen by users.
func (pc *persistConn) close(err error) {}

func (pc *persistConn) closeLocked(err error) {}

var portMap

func idnaASCIIFromURL(url *url.URL) string {}

// canonicalAddr returns url.Host but always with a ":port" suffix.
func canonicalAddr(url *url.URL) string {}

type bodyEOFSignal

var errReadOnClosedResBody

func (es *bodyEOFSignal) Read(p []byte) (n int, err error) {}

func (es *bodyEOFSignal) Close() error {}

// caller must hold es.mu.
func (es *bodyEOFSignal) condfn(err error) error {}

type gzipReader

func (gz *gzipReader) Read(p []byte) (n int, err error) {}

func (gz *gzipReader) Close() error {}

type tlsHandshakeTimeoutError

func (tlsHandshakeTimeoutError) Timeout() bool   {}

func (tlsHandshakeTimeoutError) Temporary() bool {}

func (tlsHandshakeTimeoutError) Error() string   {}

type fakeLocker

func (fakeLocker) Lock()   {}

func (fakeLocker) Unlock() {}

// cloneTLSConfig returns a shallow clone of cfg, or a new zero tls.Config if
// cfg is nil. This is safe to call even if cfg is in active use by a TLS
// client or server.
//
// cloneTLSConfig should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
//   - github.com/searKing/golang
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname cloneTLSConfig
func cloneTLSConfig(cfg *tls.Config) *tls.Config {}

type connLRU

// add adds pc to the head of the linked list.
func (cl *connLRU) add(pc *persistConn) {}

func (cl *connLRU) removeOldest() *persistConn {}

// remove removes pc from cl.
func (cl *connLRU) remove(pc *persistConn) {}

// len returns the number of items in the cache.
func (cl *connLRU) len() int {}