diff --git a/modules/graceful/net_unix.go b/modules/graceful/net_unix.go index e9c1285123..f5af1e3937 100644 --- a/modules/graceful/net_unix.go +++ b/modules/graceful/net_unix.go @@ -150,11 +150,13 @@ func CloseProvidedListeners() error { return returnableError } -// GetListener obtains a listener for the local network address. The network must be +// DefaultGetListener obtains a listener for the local network address. The network must be // a stream-oriented network: "tcp", "tcp4", "tcp6", "unix" or "unixpacket". It // returns an provided net.Listener for the matching network and address, or -// creates a new one using net.Listen. -func GetListener(network, address string) (net.Listener, error) { +// creates a new one using net.Listen. This function can be replaced by changing the +// GetListener variable at the top of this file, for example to listen on an onion service using +// github.com/cretz/bine +func DefaultGetListener(network, address string) (net.Listener, error) { // Add a deferral to say that we've tried to grab a listener defer GetManager().InformCleanup() switch network { diff --git a/modules/graceful/net_windows.go b/modules/graceful/net_windows.go index a2f58e224a..15d228d6b6 100644 --- a/modules/graceful/net_windows.go +++ b/modules/graceful/net_windows.go @@ -9,9 +9,11 @@ package graceful import "net" -// GetListener obtains a listener for the local network address. -// On windows this is basically just a shim around net.Listen. -func GetListener(network, address string) (net.Listener, error) { +// DefaultGetListener obtains a listener for the local network address. +// On windows this is basically just a shim around net.Listen. This function +// can be replaced by changing the GetListener variable at the top of this file, +// for example to listen on an onion service using github.com/cretz/bine +func DefaultGetListener(network, address string) (net.Listener, error) { // Add a deferral to say that we've tried to grab a listener defer GetManager().InformCleanup() diff --git a/modules/graceful/server.go b/modules/graceful/server.go index e42d35cd49..bd917828bc 100644 --- a/modules/graceful/server.go +++ b/modules/graceful/server.go @@ -33,6 +33,14 @@ var ( PerWriteWriteTimeoutKbTime = 10 * time.Second ) +// GetListener returns a listener from a GetListener function, which must have the +// signature: `func FunctioName(network, address string) (net.Listener, error)`. +// This determines the implementation of net.Listener which the server will use.` +// It is implemented in this way so that downstreams may specify the type of listener +// they want to provide Gitea on by default, such as with a hidden service or a p2p network +// No need to worry about "breaking" if there would be a refactoring for the Listeners. No compatibility-guarantee for this mechanism +var GetListener = DefaultGetListener + func init() { DefaultMaxHeaderBytes = 0 // use http.DefaultMaxHeaderBytes - which currently is 1 << 20 (1MB) }