mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-06-13 21:54:13 +08:00
Feat: add custom headers for http outbound
This commit is contained in:
parent
da82a41697
commit
6dc8ca3df4
@ -27,7 +27,8 @@ type SocksOutboundOptions struct {
|
||||
type HTTPOutboundOptions struct {
|
||||
DialerOptions
|
||||
ServerOptions
|
||||
Username string `json:"username,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
TLS *OutboundTLSOptions `json:"tls,omitempty"`
|
||||
Username string `json:"username,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
TLS *OutboundTLSOptions `json:"tls,omitempty"`
|
||||
Headers map[string]Listable[string] `json:"headers,omitempty"`
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package outbound
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
H "net/http"
|
||||
"os"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
@ -29,6 +30,14 @@ func NewHTTP(router adapter.Router, logger log.ContextLogger, tag string, option
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var headers H.Header
|
||||
headers = make(H.Header)
|
||||
for key, valueList := range options.Headers {
|
||||
headers.Set(key, valueList[0])
|
||||
for _, value := range valueList[1:]{
|
||||
headers.Add(key, value)
|
||||
}
|
||||
}
|
||||
return &HTTP{
|
||||
myOutboundAdapter{
|
||||
protocol: C.TypeHTTP,
|
||||
@ -37,7 +46,7 @@ func NewHTTP(router adapter.Router, logger log.ContextLogger, tag string, option
|
||||
logger: logger,
|
||||
tag: tag,
|
||||
},
|
||||
http.NewClient(detour, options.ServerOptions.Build(), options.Username, options.Password, nil),
|
||||
http.NewClient(detour, options.ServerOptions.Build(), options.Username, options.Password, headers),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user