mirror of
https://github.com/qdm12/gluetun.git
synced 2025-12-10 10:45:38 -06:00
- Faster start up - Clearer error messages - Allow for more Gluetun-specific customization - DNSSEC validation is dropped for now (it's sort of unneeded) - Fix #137
53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/qdm12/gluetun/internal/models"
|
|
)
|
|
|
|
func newHandler(ctx context.Context, logger infoWarner, logging bool,
|
|
buildInfo models.BuildInformation,
|
|
vpnLooper VPNLooper,
|
|
pfGetter PortForwardedGetter,
|
|
dnsLooper DNSLoop,
|
|
updaterLooper UpdaterLooper,
|
|
publicIPLooper PublicIPLoop,
|
|
storage Storage,
|
|
ipv6Supported bool,
|
|
) http.Handler {
|
|
handler := &handler{}
|
|
|
|
vpn := newVPNHandler(ctx, vpnLooper, storage, ipv6Supported, logger)
|
|
openvpn := newOpenvpnHandler(ctx, vpnLooper, pfGetter, logger)
|
|
dns := newDNSHandler(ctx, dnsLooper, logger)
|
|
updater := newUpdaterHandler(ctx, updaterLooper, logger)
|
|
publicip := newPublicIPHandler(publicIPLooper, logger)
|
|
|
|
handler.v0 = newHandlerV0(ctx, logger, vpnLooper, dnsLooper, updaterLooper)
|
|
handler.v1 = newHandlerV1(logger, buildInfo, vpn, openvpn, dns, updater, publicip)
|
|
|
|
handlerWithLog := withLogMiddleware(handler, logger, logging)
|
|
handler.setLogEnabled = handlerWithLog.setEnabled
|
|
|
|
return handlerWithLog
|
|
}
|
|
|
|
type handler struct {
|
|
v0 http.Handler
|
|
v1 http.Handler
|
|
setLogEnabled func(enabled bool)
|
|
}
|
|
|
|
func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
r.RequestURI = strings.TrimSuffix(r.RequestURI, "/")
|
|
if !strings.HasPrefix(r.RequestURI, "/v1/") && r.RequestURI != "/v1" {
|
|
h.v0.ServeHTTP(w, r)
|
|
return
|
|
}
|
|
r.RequestURI = strings.TrimPrefix(r.RequestURI, "/v1")
|
|
h.v1.ServeHTTP(w, r)
|
|
}
|