Weighs the soul of incoming HTTP requests to stop AI crawlers

fix: determine bind network from bind address (#714)

* fix: determine bind network from bind address

* docs: update CHANGELOG

Signed-off-by: Xe Iaso <me@xeiaso.net>

---------

Signed-off-by: Xe Iaso <me@xeiaso.net>
Co-authored-by: Xe Iaso <me@xeiaso.net>

authored by

CXM
Xe Iaso
and committed by
GitHub
35204217 ad543061

+34
+33
cmd/anubis/main.go
··· 107 107 return nil 108 108 } 109 109 110 + // parseBindNetFromAddr determine bind network and address based on the given network and address. 111 + func parseBindNetFromAddr(address string) (string, string) { 112 + defaultScheme := "http://" 113 + if !strings.Contains(address, "://") { 114 + if strings.HasPrefix(address, ":") { 115 + address = defaultScheme + "localhost" + address 116 + } else { 117 + address = defaultScheme + address 118 + } 119 + } 120 + 121 + bindUri, err := url.Parse(address) 122 + if err != nil { 123 + log.Fatal(fmt.Errorf("failed to parse bind URL: %w", err)) 124 + } 125 + 126 + switch bindUri.Scheme { 127 + case "unix": 128 + return "unix", bindUri.Path 129 + case "tcp", "http", "https": 130 + return "tcp", bindUri.Host 131 + default: 132 + log.Fatal(fmt.Errorf("unsupported network scheme %s in address %s", bindUri.Scheme, address)) 133 + } 134 + return "", address 135 + } 136 + 110 137 func setupListener(network string, address string) (net.Listener, string) { 111 138 formattedAddress := "" 139 + 140 + if network == "" { 141 + // keep compatibility 142 + network, address = parseBindNetFromAddr(address) 143 + } 144 + 112 145 switch network { 113 146 case "unix": 114 147 formattedAddress = "unix:" + address
+1
docs/docs/CHANGELOG.md
··· 11 11 12 12 ## [Unreleased] 13 13 14 + - Determine the `BIND_NETWORK`/`--bind-network` value from the bind address ([#677](https://github.com/TecharoHQ/anubis/issues/677)) 14 15 - Implement localization system. Find locale files in lib/localization/locales/. 15 16 16 17 ## v1.20.0: Thancred Waters