diff --git a/adapter/outbound/http.go b/adapter/outbound/http.go index b742510..c435bcc 100644 --- a/adapter/outbound/http.go +++ b/adapter/outbound/http.go @@ -22,18 +22,20 @@ type Http struct { user string pass string tlsConfig *tls.Config + Headers http.Header } type HttpOption struct { BasicOption - Name string `proxy:"name"` - Server string `proxy:"server"` - Port int `proxy:"port"` - UserName string `proxy:"username,omitempty"` - Password string `proxy:"password,omitempty"` - TLS bool `proxy:"tls,omitempty"` - SNI string `proxy:"sni,omitempty"` - SkipCertVerify bool `proxy:"skip-cert-verify,omitempty"` + Name string `proxy:"name"` + Server string `proxy:"server"` + Port int `proxy:"port"` + UserName string `proxy:"username,omitempty"` + Password string `proxy:"password,omitempty"` + TLS bool `proxy:"tls,omitempty"` + SNI string `proxy:"sni,omitempty"` + SkipCertVerify bool `proxy:"skip-cert-verify,omitempty"` + Headers map[string]string `proxy:"headers,omitempty"` } // StreamConn implements C.ProxyAdapter @@ -82,12 +84,12 @@ func (h *Http) shakeHand(metadata *C.Metadata, rw io.ReadWriter) error { URL: &url.URL{ Host: addr, }, - Host: addr, - Header: http.Header{ - "Proxy-Connection": []string{"Keep-Alive"}, - }, + Host: addr, + Header: h.Headers.Clone(), } + req.Header.Add("Proxy-Connection", "Keep-Alive") + if h.user != "" && h.pass != "" { auth := h.user + ":" + h.pass req.Header.Add("Proxy-Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(auth))) @@ -134,6 +136,11 @@ func NewHttp(option HttpOption) *Http { } } + headers := http.Header{} + for name, value := range option.Headers { + headers.Add(name, value) + } + return &Http{ Base: &Base{ name: option.Name, @@ -145,5 +152,6 @@ func NewHttp(option HttpOption) *Http { user: option.UserName, pass: option.Password, tlsConfig: tlsConfig, + Headers: headers, } }