From 0a4abcbbc8cfbbfa1460786dfcdd071f815f74f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Fri, 14 Apr 2023 21:18:28 +0800 Subject: [PATCH] Add headers option for HTTP outbound --- docs/configuration/outbound/http.md | 10 ++++++++++ docs/configuration/outbound/http.zh.md | 10 ++++++++++ option/simple.go | 8 +++++--- outbound/http.go | 10 ++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/docs/configuration/outbound/http.md b/docs/configuration/outbound/http.md index 40217122..c6942223 100644 --- a/docs/configuration/outbound/http.md +++ b/docs/configuration/outbound/http.md @@ -11,6 +11,8 @@ "server_port": 1080, "username": "sekai", "password": "admin", + "path": "", + "headers": {}, "tls": {}, ... // Dial Fields @@ -39,6 +41,14 @@ Basic authorization username. Basic authorization password. +#### path + +Path of HTTP request. + +#### headers + +Extra headers of HTTP request. + #### tls TLS configuration, see [TLS](/configuration/shared/tls/#outbound). diff --git a/docs/configuration/outbound/http.zh.md b/docs/configuration/outbound/http.zh.md index c633a203..53dd1b6a 100644 --- a/docs/configuration/outbound/http.zh.md +++ b/docs/configuration/outbound/http.zh.md @@ -11,6 +11,8 @@ "server_port": 1080, "username": "sekai", "password": "admin", + "path": "", + "headers": {}, "tls": {}, ... // 拨号字段 @@ -39,6 +41,14 @@ Basic 认证用户名。 Basic 认证密码。 +#### path + +HTTP 请求路径。 + +#### headers + +HTTP 请求的额外标头。 + #### tls TLS 配置, 参阅 [TLS](/zh/configuration/shared/tls/#outbound)。 diff --git a/option/simple.go b/option/simple.go index eede0512..dec1e0e0 100644 --- a/option/simple.go +++ b/option/simple.go @@ -27,7 +27,9 @@ 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"` + Path string `json:"path,omitempty"` + Headers map[string]Listable[string] `json:"headers,omitempty"` } diff --git a/outbound/http.go b/outbound/http.go index 334fcc35..019cb37e 100644 --- a/outbound/http.go +++ b/outbound/http.go @@ -3,6 +3,7 @@ package outbound import ( "context" "net" + "net/http" "os" "github.com/sagernet/sing-box/adapter" @@ -29,6 +30,13 @@ func NewHTTP(router adapter.Router, logger log.ContextLogger, tag string, option if err != nil { 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{ myOutboundAdapter{ protocol: C.TypeHTTP, @@ -42,6 +50,8 @@ func NewHTTP(router adapter.Router, logger log.ContextLogger, tag string, option Server: options.ServerOptions.Build(), Username: options.Username, Password: options.Password, + Path: options.Path, + Headers: headers, }), }, nil }