From d4e7ba0df206c02afeb627ff5579b856ab2607f3 Mon Sep 17 00:00:00 2001 From: Gerhard Tan Date: Wed, 10 Jul 2024 03:02:44 +0000 Subject: [PATCH] Add http2http client plugin --- pkg/config/client.go | 6 +++--- pkg/config/conversion.go | 13 +++++++++++++ pkg/consts/config.go | 6 +++--- ui/editproxy.go | 2 +- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/pkg/config/client.go b/pkg/config/client.go index ada1f199..345b8864 100644 --- a/pkg/config/client.go +++ b/pkg/config/client.go @@ -164,10 +164,10 @@ type BaseProxyConf struct { } type PluginParams struct { - PluginLocalAddr string `ini:"plugin_local_addr,omitempty" http2https:"true" https2https:"true" https2http:"true"` + PluginLocalAddr string `ini:"plugin_local_addr,omitempty" http2https:"true" http2http:"true" https2https:"true" https2http:"true"` PluginCrtPath string `ini:"plugin_crt_path,omitempty" https2https:"true" https2http:"true"` PluginKeyPath string `ini:"plugin_key_path,omitempty" https2https:"true" https2http:"true"` - PluginHostHeaderRewrite string `ini:"plugin_host_header_rewrite,omitempty" http2https:"true" https2https:"true" https2http:"true"` + PluginHostHeaderRewrite string `ini:"plugin_host_header_rewrite,omitempty" http2https:"true" http2http:"true" https2https:"true" https2http:"true"` PluginHttpUser string `ini:"plugin_http_user,omitempty" http_proxy:"true" static_file:"true"` PluginHttpPasswd string `ini:"plugin_http_passwd,omitempty" http_proxy:"true" static_file:"true"` PluginUser string `ini:"plugin_user,omitempty" socks5:"true"` @@ -175,7 +175,7 @@ type PluginParams struct { PluginLocalPath string `ini:"plugin_local_path,omitempty" static_file:"true"` PluginStripPrefix string `ini:"plugin_strip_prefix,omitempty" static_file:"true"` PluginUnixPath string `ini:"plugin_unix_path,omitempty" unix_domain_socket:"true"` - PluginHeaders map[string]string `ini:"-" http2https:"true" https2https:"true" https2http:"true"` + PluginHeaders map[string]string `ini:"-" http2https:"true" http2http:"true" https2https:"true" https2http:"true"` } // HealthCheckConf configures health checking. This can be useful for load diff --git a/pkg/config/conversion.go b/pkg/config/conversion.go index f71ebdb3..0e1877e8 100644 --- a/pkg/config/conversion.go +++ b/pkg/config/conversion.go @@ -189,6 +189,10 @@ func clientProxyBaseFromV1(c *v1.ProxyBaseConfig, out *Proxy) { out.PluginLocalAddr = v.LocalAddr out.PluginHostHeaderRewrite = v.HostHeaderRewrite out.PluginHeaders = v.RequestHeaders.Set + case *v1.HTTP2HTTPPluginOptions: + out.PluginLocalAddr = v.LocalAddr + out.PluginHostHeaderRewrite = v.HostHeaderRewrite + out.PluginHeaders = v.RequestHeaders.Set case *v1.HTTPProxyPluginOptions: out.PluginHttpUser = v.HTTPUser out.PluginHttpPasswd = v.HTTPPassword @@ -508,6 +512,15 @@ func clientProxyBaseToV1(c *BaseProxyConf) (v1.ProxyBaseConfig, error) { Set: c.PluginHeaders, }, } + case consts.PluginHttp2Http: + r.ProxyBackend.Plugin.ClientPluginOptions = &v1.HTTP2HTTPPluginOptions{ + Type: c.Plugin, + LocalAddr: c.PluginLocalAddr, + HostHeaderRewrite: c.PluginHostHeaderRewrite, + RequestHeaders: v1.HeaderOperations{ + Set: c.PluginHeaders, + }, + } case consts.PluginHttpProxy: r.ProxyBackend.Plugin.ClientPluginOptions = &v1.HTTPProxyPluginOptions{ Type: c.Plugin, diff --git a/pkg/consts/config.go b/pkg/consts/config.go index 10269c87..c2b47bc4 100644 --- a/pkg/consts/config.go +++ b/pkg/consts/config.go @@ -42,13 +42,13 @@ const ( PluginHttps2Http = "https2http" PluginHttps2Https = "https2https" PluginHttp2Https = "http2https" + PluginHttp2Http = "http2http" PluginUnixDomain = "unix_domain_socket" ) var PluginTypes = []string{ - PluginHttpProxy, PluginSocks5, PluginStaticFile, - PluginHttps2Http, PluginHttps2Https, PluginHttp2Https, - PluginUnixDomain, + PluginHttp2Https, PluginHttp2Http, PluginHttps2Http, PluginHttps2Https, + PluginHttpProxy, PluginSocks5, PluginStaticFile, PluginUnixDomain, } // Auth methods diff --git a/ui/editproxy.go b/ui/editproxy.go index e4e6a7b0..23917003 100644 --- a/ui/editproxy.go +++ b/ui/editproxy.go @@ -594,7 +594,7 @@ func (pd *EditProxyDialog) switchType() { case consts.PluginHttps2Http, consts.PluginHttps2Https: pd.viewModel.PluginHTTPFwdVisible = true pd.viewModel.PluginCertVisible = true - case consts.PluginHttp2Https: + case consts.PluginHttp2Https, consts.PluginHttp2Http: pd.viewModel.PluginHTTPFwdVisible = true } }