Skip to content

Commit e6895e8

Browse files
joshariandsnet
authored andcommitted
[tailscale1.18] net/http: add Transport.OnProxyConnectResponse for debugging
Change-Id: I114abf13920e3e91bfe8603e787aae219045137d
1 parent c85adc8 commit e6895e8

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

api/go1.tailscale.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pkg net/http, type Transport struct, OnProxyConnectResponse func(context.Context, *url.URL, *Request, *Response) error

src/net/http/transport.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,11 @@ type Transport struct {
252252
// ignored.
253253
GetProxyConnectHeader func(ctx context.Context, proxyURL *url.URL, target string) (Header, error)
254254

255+
// OnProxyConnectResponse is called when the Transport gets an HTTP response from
256+
// a proxy for a CONNECT request. It's called before the check for a 200 OK response.
257+
// If it returns an error, the request fails with that error.
258+
OnProxyConnectResponse func(ctx context.Context, proxyURL *url.URL, connectReq *Request, connectRes *Response) error
259+
255260
// MaxResponseHeaderBytes specifies a limit on how many
256261
// response bytes are allowed in the server's response
257262
// header.
@@ -324,6 +329,7 @@ func (t *Transport) Clone() *Transport {
324329
ExpectContinueTimeout: t.ExpectContinueTimeout,
325330
ProxyConnectHeader: t.ProxyConnectHeader.Clone(),
326331
GetProxyConnectHeader: t.GetProxyConnectHeader,
332+
OnProxyConnectResponse: t.OnProxyConnectResponse,
327333
MaxResponseHeaderBytes: t.MaxResponseHeaderBytes,
328334
ForceAttemptHTTP2: t.ForceAttemptHTTP2,
329335
WriteBufferSize: t.WriteBufferSize,
@@ -1717,6 +1723,11 @@ func (t *Transport) dialConn(ctx context.Context, cm connectMethod) (pconn *pers
17171723
conn.Close()
17181724
return nil, err
17191725
}
1726+
if f := t.OnProxyConnectResponse; f != nil {
1727+
if err := f(ctx, cm.proxyURL, connectReq, resp); err != nil {
1728+
return nil, err
1729+
}
1730+
}
17201731
if resp.StatusCode != 200 {
17211732
_, text, ok := strings.Cut(resp.Status, " ")
17221733
conn.Close()

src/net/http/transport_test.go

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5878,23 +5878,26 @@ func TestTransportRequestWriteRoundTrip(t *testing.T) {
58785878

58795879
func TestTransportClone(t *testing.T) {
58805880
tr := &Transport{
5881-
Proxy: func(*Request) (*url.URL, error) { panic("") },
5882-
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) { panic("") },
5883-
Dial: func(network, addr string) (net.Conn, error) { panic("") },
5884-
DialTLS: func(network, addr string) (net.Conn, error) { panic("") },
5885-
DialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) { panic("") },
5886-
TLSClientConfig: new(tls.Config),
5887-
TLSHandshakeTimeout: time.Second,
5888-
DisableKeepAlives: true,
5889-
DisableCompression: true,
5890-
MaxIdleConns: 1,
5891-
MaxIdleConnsPerHost: 1,
5892-
MaxConnsPerHost: 1,
5893-
IdleConnTimeout: time.Second,
5894-
ResponseHeaderTimeout: time.Second,
5895-
ExpectContinueTimeout: time.Second,
5896-
ProxyConnectHeader: Header{},
5897-
GetProxyConnectHeader: func(context.Context, *url.URL, string) (Header, error) { return nil, nil },
5881+
Proxy: func(*Request) (*url.URL, error) { panic("") },
5882+
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) { panic("") },
5883+
Dial: func(network, addr string) (net.Conn, error) { panic("") },
5884+
DialTLS: func(network, addr string) (net.Conn, error) { panic("") },
5885+
DialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) { panic("") },
5886+
TLSClientConfig: new(tls.Config),
5887+
TLSHandshakeTimeout: time.Second,
5888+
DisableKeepAlives: true,
5889+
DisableCompression: true,
5890+
MaxIdleConns: 1,
5891+
MaxIdleConnsPerHost: 1,
5892+
MaxConnsPerHost: 1,
5893+
IdleConnTimeout: time.Second,
5894+
ResponseHeaderTimeout: time.Second,
5895+
ExpectContinueTimeout: time.Second,
5896+
ProxyConnectHeader: Header{},
5897+
GetProxyConnectHeader: func(context.Context, *url.URL, string) (Header, error) { return nil, nil },
5898+
OnProxyConnectResponse: func(ctx context.Context, proxyURL *url.URL, connectReq *Request, connectRes *Response) error {
5899+
return nil
5900+
},
58985901
MaxResponseHeaderBytes: 1,
58995902
ForceAttemptHTTP2: true,
59005903
TLSNextProto: map[string]func(authority string, c *tls.Conn) RoundTripper{

0 commit comments

Comments
 (0)