lib/httpserver: move ServeWithOpts to Serve

This addresses that todo in the codebase, and updates all callsites to
the new signature.

---------
Signed-off-by: Florian Klink <flokli@flokli.de>
This commit is contained in:
Florian Klink
2025-05-06 18:41:44 +03:00
committed by GitHub
parent 57164920e3
commit 0e313e5355
8 changed files with 17 additions and 37 deletions

View File

@@ -102,35 +102,7 @@ type ServeOptions struct {
// Serve starts an http server on the given addrs with the given optional rh.
//
// By default all the responses are transparently compressed, since egress traffic is usually expensive.
//
// The compression can be disabled by specifying -http.disableResponseCompression command-line flag.
//
// If useProxyProtocol is set to true for the corresponding addr, then the incoming connections are accepted via proxy protocol.
// See https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt
func Serve(addrs []string, useProxyProtocol *flagutil.ArrayBool, rh RequestHandler) {
if rh == nil {
rh = func(_ http.ResponseWriter, _ *http.Request) bool {
return false
}
}
opts := ServeOptions{
UseProxyProtocol: useProxyProtocol,
}
for idx, addr := range addrs {
if addr == "" {
continue
}
go serve(addr, rh, idx, opts)
}
}
// ServeWithOpts starts an http server on the given addrs with the given optional request handlers.
//
// By default all the responses are transparently compressed, since egress traffic is usually expensive.
//
// The compression can be disabled by specifying -http.disableResponseCompression command-line flag.
// TODO: rename to Serve and update Serve usage with new signature
func ServeWithOpts(addrs []string, rh RequestHandler, opts ServeOptions) {
func Serve(addrs []string, rh RequestHandler, opts ServeOptions) {
if rh == nil {
rh = func(_ http.ResponseWriter, _ *http.Request) bool {
return false