mirror of https://github.com/Dreamacro/clash.git
Feature: allow http outbound to set custom headers (#2647)
This commit is contained in:
parent
7e2974f02f
commit
a7252a1576
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue