From f49d160447899270fbca6370cb7ab2742dce85dc Mon Sep 17 00:00:00 2001 From: mscherer Date: Mon, 6 Dec 2021 05:46:11 +0100 Subject: [PATCH] Replace "unix" by "http+unix" for PROTOCOL (#17771) --- cmd/web.go | 6 +-- .../doc/advanced/config-cheat-sheet.en-us.md | 6 +-- modules/private/internal.go | 2 +- modules/setting/setting.go | 39 +++++++++---------- 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/cmd/web.go b/cmd/web.go index fbd62191a6..137c56d962 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -180,7 +180,7 @@ func setPort(port string) error { setting.HTTPPort = port switch setting.Protocol { - case setting.UnixSocket: + case setting.HTTPUnix: case setting.FCGI: case setting.FCGIUnix: default: @@ -202,7 +202,7 @@ func setPort(port string) error { func listen(m http.Handler, handleRedirector bool) error { listenAddr := setting.HTTPAddr - if setting.Protocol != setting.UnixSocket && setting.Protocol != setting.FCGIUnix { + if setting.Protocol != setting.HTTPUnix && setting.Protocol != setting.FCGIUnix { listenAddr = net.JoinHostPort(listenAddr, setting.HTTPPort) } log.Info("Listen: %v://%s%s", setting.Protocol, listenAddr, setting.AppSubURL) @@ -240,7 +240,7 @@ func listen(m http.Handler, handleRedirector bool) error { NoHTTPRedirector() } err = runFCGI("tcp", listenAddr, "FCGI Web", m) - case setting.UnixSocket: + case setting.HTTPUnix: if handleRedirector { NoHTTPRedirector() } diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 030ca7b36b..bb2eb1c8ca 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -233,7 +233,7 @@ The following configuration set `Content-Type: application/vnd.android.package-a ## Server (`server`) -- `PROTOCOL`: **http**: \[http, https, fcgi, unix, fcgi+unix\] +- `PROTOCOL`: **http**: \[http, https, fcgi, http+unix, fcgi+unix\] - `DOMAIN`: **localhost**: Domain name of this server. - `ROOT_URL`: **%(PROTOCOL)s://%(DOMAIN)s:%(HTTP\_PORT)s/**: Overwrite the automatically generated public URL. @@ -248,7 +248,7 @@ The following configuration set `Content-Type: application/vnd.android.package-a - `HTTP_ADDR`: **0.0.0.0**: HTTP listen address. - If `PROTOCOL` is set to `fcgi`, Gitea will listen for FastCGI requests on TCP socket defined by `HTTP_ADDR` and `HTTP_PORT` configuration settings. - - If `PROTOCOL` is set to `unix` or `fcgi+unix`, this should be the name of the Unix socket file to use. Relative paths will be made absolute against the AppWorkPath. + - If `PROTOCOL` is set to `http+unix` or `fcgi+unix`, this should be the name of the Unix socket file to use. Relative paths will be made absolute against the AppWorkPath. - `HTTP_PORT`: **3000**: HTTP listen port. - If `PROTOCOL` is set to `fcgi`, Gitea will listen for FastCGI requests on TCP socket defined by `HTTP_ADDR` and `HTTP_PORT` configuration settings. @@ -257,7 +257,7 @@ The following configuration set `Content-Type: application/vnd.android.package-a (DMZ) URL for Gitea workers (such as SSH update) accessing web service. In most cases you do not need to change the default value. Alter it only if your SSH server node is not the same as HTTP node. Do not set this variable - if `PROTOCOL` is set to `unix`. + if `PROTOCOL` is set to `http+unix`. - `PER_WRITE_TIMEOUT`: **30s**: Timeout for any write to the connection. (Set to 0 to disable all timeouts.) - `PER_WRITE_PER_KB_TIMEOUT`: **10s**: Timeout per Kb written to connections. diff --git a/modules/private/internal.go b/modules/private/internal.go index 0a39ca7b8e..a77a990627 100644 --- a/modules/private/internal.go +++ b/modules/private/internal.go @@ -46,7 +46,7 @@ func newInternalRequest(ctx context.Context, url, method string) *httplib.Reques InsecureSkipVerify: true, ServerName: setting.Domain, }) - if setting.Protocol == setting.UnixSocket { + if setting.Protocol == setting.HTTPUnix { req.SetTransport(&http.Transport{ DialContext: func(ctx context.Context, _, _ string) (net.Conn, error) { var d net.Dialer diff --git a/modules/setting/setting.go b/modules/setting/setting.go index d219dbaafd..8b67a45175 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -39,11 +39,11 @@ type Scheme string // enumerates all the scheme types const ( - HTTP Scheme = "http" - HTTPS Scheme = "https" - FCGI Scheme = "fcgi" - FCGIUnix Scheme = "fcgi+unix" - UnixSocket Scheme = "unix" + HTTP Scheme = "http" + HTTPS Scheme = "https" + FCGI Scheme = "fcgi" + FCGIUnix Scheme = "fcgi+unix" + HTTPUnix Scheme = "http+unix" ) // LandingPage describes the default page @@ -607,7 +607,8 @@ func loadFromConf(allowEmpty bool) { HTTPPort = sec.Key("HTTP_PORT").MustString("3000") Protocol = HTTP - switch sec.Key("PROTOCOL").String() { + protocolCfg := sec.Key("PROTOCOL").String() + switch protocolCfg { case "https": Protocol = HTTPS CertFile = sec.Key("CERT_FILE").String() @@ -620,24 +621,22 @@ func loadFromConf(allowEmpty bool) { } case "fcgi": Protocol = FCGI - case "fcgi+unix": - Protocol = FCGIUnix - UnixSocketPermissionRaw := sec.Key("UNIX_SOCKET_PERMISSION").MustString("666") - UnixSocketPermissionParsed, err := strconv.ParseUint(UnixSocketPermissionRaw, 8, 32) - if err != nil || UnixSocketPermissionParsed > 0777 { - log.Fatal("Failed to parse unixSocketPermission: %s", UnixSocketPermissionRaw) - } - UnixSocketPermission = uint32(UnixSocketPermissionParsed) - if !filepath.IsAbs(HTTPAddr) { - HTTPAddr = filepath.Join(AppWorkPath, HTTPAddr) - } - case "unix": - Protocol = UnixSocket + case "fcgi+unix", "unix", "http+unix": + switch protocolCfg { + case "fcgi+unix": + Protocol = FCGIUnix + case "unix": + log.Warn("unix PROTOCOL value is deprecated, please use http+unix") + fallthrough + case "http+unix": + Protocol = HTTPUnix + } UnixSocketPermissionRaw := sec.Key("UNIX_SOCKET_PERMISSION").MustString("666") UnixSocketPermissionParsed, err := strconv.ParseUint(UnixSocketPermissionRaw, 8, 32) if err != nil || UnixSocketPermissionParsed > 0777 { log.Fatal("Failed to parse unixSocketPermission: %s", UnixSocketPermissionRaw) } + UnixSocketPermission = uint32(UnixSocketPermissionParsed) if !filepath.IsAbs(HTTPAddr) { HTTPAddr = filepath.Join(AppWorkPath, HTTPAddr) @@ -692,7 +691,7 @@ func loadFromConf(allowEmpty bool) { var defaultLocalURL string switch Protocol { - case UnixSocket: + case HTTPUnix: defaultLocalURL = "http://unix/" case FCGI: defaultLocalURL = AppURL