mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-02-16 14:24:31 +00:00
Add headers option for HTTP outbound
This commit is contained in:
parent
b491c350ae
commit
0a4abcbbc8
|
@ -11,6 +11,8 @@
|
||||||
"server_port": 1080,
|
"server_port": 1080,
|
||||||
"username": "sekai",
|
"username": "sekai",
|
||||||
"password": "admin",
|
"password": "admin",
|
||||||
|
"path": "",
|
||||||
|
"headers": {},
|
||||||
"tls": {},
|
"tls": {},
|
||||||
|
|
||||||
... // Dial Fields
|
... // Dial Fields
|
||||||
|
@ -39,6 +41,14 @@ Basic authorization username.
|
||||||
|
|
||||||
Basic authorization password.
|
Basic authorization password.
|
||||||
|
|
||||||
|
#### path
|
||||||
|
|
||||||
|
Path of HTTP request.
|
||||||
|
|
||||||
|
#### headers
|
||||||
|
|
||||||
|
Extra headers of HTTP request.
|
||||||
|
|
||||||
#### tls
|
#### tls
|
||||||
|
|
||||||
TLS configuration, see [TLS](/configuration/shared/tls/#outbound).
|
TLS configuration, see [TLS](/configuration/shared/tls/#outbound).
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
"server_port": 1080,
|
"server_port": 1080,
|
||||||
"username": "sekai",
|
"username": "sekai",
|
||||||
"password": "admin",
|
"password": "admin",
|
||||||
|
"path": "",
|
||||||
|
"headers": {},
|
||||||
"tls": {},
|
"tls": {},
|
||||||
|
|
||||||
... // 拨号字段
|
... // 拨号字段
|
||||||
|
@ -39,6 +41,14 @@ Basic 认证用户名。
|
||||||
|
|
||||||
Basic 认证密码。
|
Basic 认证密码。
|
||||||
|
|
||||||
|
#### path
|
||||||
|
|
||||||
|
HTTP 请求路径。
|
||||||
|
|
||||||
|
#### headers
|
||||||
|
|
||||||
|
HTTP 请求的额外标头。
|
||||||
|
|
||||||
#### tls
|
#### tls
|
||||||
|
|
||||||
TLS 配置, 参阅 [TLS](/zh/configuration/shared/tls/#outbound)。
|
TLS 配置, 参阅 [TLS](/zh/configuration/shared/tls/#outbound)。
|
||||||
|
|
|
@ -27,7 +27,9 @@ type SocksOutboundOptions struct {
|
||||||
type HTTPOutboundOptions struct {
|
type HTTPOutboundOptions struct {
|
||||||
DialerOptions
|
DialerOptions
|
||||||
ServerOptions
|
ServerOptions
|
||||||
Username string `json:"username,omitempty"`
|
Username string `json:"username,omitempty"`
|
||||||
Password string `json:"password,omitempty"`
|
Password string `json:"password,omitempty"`
|
||||||
TLS *OutboundTLSOptions `json:"tls,omitempty"`
|
TLS *OutboundTLSOptions `json:"tls,omitempty"`
|
||||||
|
Path string `json:"path,omitempty"`
|
||||||
|
Headers map[string]Listable[string] `json:"headers,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package outbound
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net"
|
"net"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/sagernet/sing-box/adapter"
|
"github.com/sagernet/sing-box/adapter"
|
||||||
|
@ -29,6 +30,13 @@ func NewHTTP(router adapter.Router, logger log.ContextLogger, tag string, option
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
var headers http.Header
|
||||||
|
if options.Headers != nil {
|
||||||
|
headers = make(http.Header)
|
||||||
|
for key, values := range options.Headers {
|
||||||
|
headers[key] = values
|
||||||
|
}
|
||||||
|
}
|
||||||
return &HTTP{
|
return &HTTP{
|
||||||
myOutboundAdapter{
|
myOutboundAdapter{
|
||||||
protocol: C.TypeHTTP,
|
protocol: C.TypeHTTP,
|
||||||
|
@ -42,6 +50,8 @@ func NewHTTP(router adapter.Router, logger log.ContextLogger, tag string, option
|
||||||
Server: options.ServerOptions.Build(),
|
Server: options.ServerOptions.Build(),
|
||||||
Username: options.Username,
|
Username: options.Username,
|
||||||
Password: options.Password,
|
Password: options.Password,
|
||||||
|
Path: options.Path,
|
||||||
|
Headers: headers,
|
||||||
}),
|
}),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue