@@ -14,21 +14,29 @@ import (
14
14
"strings"
15
15
)
16
16
17
- type netDialerFunc func (network , addr string ) (net.Conn , error )
17
+ type netDialer struct {
18
+ proxyHeader http.Header
19
+ f func (network , addr string ) (net.Conn , error )
20
+ }
18
21
19
- func (fn netDialerFunc ) Dial (network , addr string ) (net.Conn , error ) {
20
- return fn (network , addr )
22
+ func (n netDialer ) Dial (network , addr string ) (net.Conn , error ) {
23
+ return n . f (network , addr )
21
24
}
22
25
23
26
func init () {
24
27
proxy_RegisterDialerType ("http" , func (proxyURL * url.URL , forwardDialer proxy_Dialer ) (proxy_Dialer , error ) {
25
- return & httpProxyDialer {proxyURL : proxyURL , forwardDial : forwardDialer .Dial }, nil
28
+ p , ok := forwardDialer .(* netDialer )
29
+ if ! ok {
30
+ return nil , errors .New ("type assertion failed when ini proxy info" )
31
+ }
32
+ return & httpProxyDialer {proxyURL : proxyURL , forwardDial : forwardDialer .Dial , proxyHeader : p .proxyHeader }, nil
26
33
})
27
34
}
28
35
29
36
type httpProxyDialer struct {
30
37
proxyURL * url.URL
31
38
forwardDial func (network , addr string ) (net.Conn , error )
39
+ proxyHeader http.Header
32
40
}
33
41
34
42
func (hpd * httpProxyDialer ) Dial (network string , addr string ) (net.Conn , error ) {
@@ -47,6 +55,10 @@ func (hpd *httpProxyDialer) Dial(network string, addr string) (net.Conn, error)
47
55
}
48
56
}
49
57
58
+ for k , v := range hpd .proxyHeader {
59
+ connectHeader [k ] = v
60
+ }
61
+
50
62
connectReq := & http.Request {
51
63
Method : "CONNECT" ,
52
64
URL : & url.URL {Opaque : addr },
0 commit comments