move setup of fastServer into own func

pull/18/head
6543 2021-12-05 15:09:21 +01:00
rodzic b3830e979c
commit bb6f28fe57
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: C99B82E40B027BAE
2 zmienionych plików z 26 dodań i 14 usunięć

Wyświetl plik

@ -8,7 +8,6 @@ import (
"net"
"net/http"
"strings"
"time"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
@ -77,19 +76,7 @@ func Serve(ctx *cli.Context) error {
BlacklistedPaths, allowedCorsDomains,
dnsLookupCache, canonicalDomainCache)
// Enable compression by wrapping the handler with the compression function provided by FastHTTP
compressedHandler := fasthttp.CompressHandlerBrotliLevel(handler, fasthttp.CompressBrotliBestSpeed, fasthttp.CompressBestSpeed)
fastServer := &fasthttp.Server{
Handler: compressedHandler,
DisablePreParseMultipartForm: true,
MaxRequestBodySize: 0,
NoDefaultServerHeader: true,
NoDefaultDate: true,
ReadTimeout: 30 * time.Second, // needs to be this high for ACME certificates with ZeroSSL & HTTP-01 challenge
Concurrency: 1024 * 32, // TODO: adjust bottlenecks for best performance with Gitea!
MaxConnsPerIP: 100,
}
fastServer, err := server.SetupServer(handler)
// Setup listener and TLS
log.Info().Msgf("Listening on https://%s", listeningAddress)

25
server/setup.go 100644
Wyświetl plik

@ -0,0 +1,25 @@
package server
import (
"time"
"github.com/valyala/fasthttp"
)
func SetupServer(handler fasthttp.RequestHandler) (*fasthttp.Server, error) {
// Enable compression by wrapping the handler with the compression function provided by FastHTTP
compressedHandler := fasthttp.CompressHandlerBrotliLevel(handler, fasthttp.CompressBrotliBestSpeed, fasthttp.CompressBestSpeed)
fastServer := &fasthttp.Server{
Handler: compressedHandler,
DisablePreParseMultipartForm: true,
MaxRequestBodySize: 0,
NoDefaultServerHeader: true,
NoDefaultDate: true,
ReadTimeout: 30 * time.Second, // needs to be this high for ACME certificates with ZeroSSL & HTTP-01 challenge
Concurrency: 1024 * 32, // TODO: adjust bottlenecks for best performance with Gitea!
MaxConnsPerIP: 100,
}
return fastServer, nil
}