From bb6f28fe570793872ab2b60a8ff706459f3e1feb Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sun, 5 Dec 2021 15:09:21 +0100 Subject: [PATCH] move setup of fastServer into own func --- cmd/main.go | 15 +-------------- server/setup.go | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 server/setup.go diff --git a/cmd/main.go b/cmd/main.go index e40e385..f4ee205 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -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) diff --git a/server/setup.go b/server/setup.go new file mode 100644 index 0000000..6986c7c --- /dev/null +++ b/server/setup.go @@ -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 +}