diff --git a/src/def.go b/src/def.go index 4a9ae97..5c54c26 100644 --- a/src/def.go +++ b/src/def.go @@ -87,6 +87,10 @@ var ( allowWebFileManager = flag.Bool("webfm", true, "Enable web file manager for static web server root folder") enableAutoUpdate = flag.Bool("cfgupgrade", true, "Enable auto config upgrade if breaking change is detected") + /* Default Configuration Flags */ + defaultInboundPort = flag.Int("default_inbound_port", 443, "Default web server listening port") + defaultEnableInboundTraffic = flag.Bool("default_inbound_enabled", true, "If web server is enabled by default") + /* Path Configuration Flags */ //path_database = flag.String("dbpath", "./sys.db", "Database path") //path_conf = flag.String("conf", "./conf", "Configuration folder path") diff --git a/src/mod/dynamicproxy/dpcore/dpcore.go b/src/mod/dynamicproxy/dpcore/dpcore.go index 5ae55bc..14a425e 100644 --- a/src/mod/dynamicproxy/dpcore/dpcore.go +++ b/src/mod/dynamicproxy/dpcore/dpcore.go @@ -2,6 +2,7 @@ package dpcore import ( "context" + "crypto/tls" "errors" "io" "log" @@ -11,6 +12,7 @@ import ( "strings" "time" + "golang.org/x/net/http2" "imuslab.com/zoraxy/mod/dynamicproxy/domainsniff" "imuslab.com/zoraxy/mod/dynamicproxy/permissionpolicy" ) @@ -84,6 +86,7 @@ type requestCanceler interface { type DpcoreOptions struct { IgnoreTLSVerification bool //Disable all TLS verification when request pass through this proxy router FlushInterval time.Duration //Duration to flush in normal requests. Stream request or keep-alive request will always flush with interval of -1 (immediately) + UseH2CRoundTripper bool //Use H2C RoundTripper for HTTP/2.0 connection } func NewDynamicProxyCore(target *url.URL, prepender string, dpcOptions *DpcoreOptions) *ReverseProxy { @@ -100,8 +103,17 @@ func NewDynamicProxyCore(target *url.URL, prepender string, dpcOptions *DpcoreOp } - //Hack the default transporter to handle more connections thisTransporter := http.DefaultTransport + if dpcOptions.UseH2CRoundTripper { + thisTransporter = &http2.Transport{ + DialTLS: func(network, addr string, cfg *tls.Config) (net.Conn, error) { + return net.Dial(network, addr) + }, + AllowHTTP: true, + } + } + + //Hack the default transporter to handle more connections optimalConcurrentConnection := 32 thisTransporter.(*http.Transport).MaxIdleConns = optimalConcurrentConnection * 2 thisTransporter.(*http.Transport).MaxIdleConnsPerHost = optimalConcurrentConnection diff --git a/src/reverseproxy.go b/src/reverseproxy.go index fb22cf6..3ecdcb2 100644 --- a/src/reverseproxy.go +++ b/src/reverseproxy.go @@ -28,8 +28,8 @@ func ReverseProxtInit() { /* Load Reverse Proxy Global Settings */ - inboundPort := 443 - autoStartReverseProxy := true + inboundPort := *defaultInboundPort + autoStartReverseProxy := *defaultEnableInboundTraffic if sysdb.KeyExists("settings", "inbound") { //Read settings from database sysdb.Read("settings", "inbound", &inboundPort) @@ -42,8 +42,8 @@ func ReverseProxtInit() { } else { //Default port if netutils.CheckIfPortOccupied(inboundPort) { - inboundPort = 8743 - SystemWideLogger.Println("Port 443 is occupied. Switching to backup port 8743 instead") + autoStartReverseProxy = false + SystemWideLogger.Println("Port 443 is occupied. Change the listening port in the webmin panel and press \"Start Service\" to start reverse proxy service") } SystemWideLogger.Println("Inbound port not set. Using default (443)") }