Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Configurable "User-Agent" for SIP003 v2ray transport #2227

Open
zedifen opened this issue Oct 28, 2024 · 1 comment
Open

Comments

@zedifen
Copy link
Contributor

zedifen commented Oct 28, 2024

Custom headers is allowed in V2ray WebSocket transport. However for Shadowsocks outbounds, currently it's not possible to configure them through plugin_opts.

Setting User-Agent (or other headers) might be useful for server to distinguish clients (e.g. identifying sing-box client against web browsers / scrapers) so the sever can then choose to provide service or not.

It's not hard to read an additional argument from plugin_opts and apply it to option.V2RayTransportOptions. I made a simple patch as below and it's working.

diff --git a/transport/sip003/v2ray.go b/transport/sip003/v2ray.go
index 078adea278..afda3f15db 100644
--- a/transport/sip003/v2ray.go
+++ b/transport/sip003/v2ray.go
@@ -49,6 +49,7 @@ func newV2RayPlugin(ctx context.Context, pluginOpts Args, router adapter.Router,
 
 	host := "cloudfront.com"
 	path := "/"
+	userAgent := "Go-http-client/1.1 sing-box/1.10 SingBox/1.10"
 
 	if hostOpt, loaded := pluginOpts.Get("host"); loaded {
 		host = hostOpt
@@ -57,6 +58,9 @@ func newV2RayPlugin(ctx context.Context, pluginOpts Args, router adapter.Router,
 	if pathOpt, loaded := pluginOpts.Get("path"); loaded {
 		path = pathOpt
 	}
+	if userAgentOpt, loaded := pluginOpts.Get("userAgent"); loaded {
+		userAgent = userAgentOpt
+	}
 
 	var tlsClient tls.Config
 	var err error
@@ -76,6 +80,7 @@ func newV2RayPlugin(ctx context.Context, pluginOpts Args, router adapter.Router,
 			WebsocketOptions: option.V2RayWebsocketOptions{
 				Headers: map[string]option.Listable[string]{
 					"Host": []string{host},
+					"User-Agent": []string{userAgent},
 				},
 				Path: path,
 			},
@junx964
Copy link

junx964 commented Oct 31, 2024

Support. Looking forward to the update merge.
Looking forward to shadowsocks support
I am currently using simple-obfs to reverse the generation, and I am tired

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants