Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(327)

Unified Diff: src/pkg/http/transport.go

Issue 4536091: code review 4536091: http: let Transport use a custom net.Dial function (Closed)
Patch Set: diff -r bd3cf9bc3480 https://go.googlecode.com/hg/ Created 13 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pkg/http/transport.go
===================================================================
--- a/src/pkg/http/transport.go
+++ b/src/pkg/http/transport.go
@@ -42,12 +42,17 @@
// TODO: tunable on timeout on cached connections
// TODO: optional pipelining
- // Proxy optionally 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 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, os.Error)
+ // Dial specifies the dial function for creating TCP
+ // connections.
+ // If Dial is nil, net.Dial is used.
+ Dial func(net, addr string) (c net.Conn, err os.Error)
+
DisableKeepAlives bool
DisableCompression bool
@@ -255,6 +260,13 @@
return
}
+func (t *Transport) dial(network, addr string) (c net.Conn, err os.Error) {
+ if t.Dial != nil {
+ return t.Dial(network, addr)
+ }
+ return net.Dial(network, addr)
+}
+
// 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
@@ -264,7 +276,7 @@
return pc, nil
}
- conn, err := net.Dial("tcp", cm.addr())
+ conn, err := t.dial("tcp", cm.addr())
if err != nil {
if cm.proxyURL != nil {
err = fmt.Errorf("http: error connecting to proxy %s: %v", cm.proxyURL, err)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b