3 Commits

Author SHA1 Message Date
13f95ee895 Allow real IP from loopback AND private
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone/tag Build is passing
2022-03-30 22:58:15 -04:00
99c0137034 Fix redirect handler (again) to use notfound
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2022-03-30 22:16:50 -04:00
64551704a3 Use proper methods and fix redirect handler
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2022-03-30 22:08:51 -04:00
2 changed files with 10 additions and 7 deletions

13
main.go
View File

@ -114,12 +114,13 @@ func main() {
r.Use(RealIPMiddleware) r.Use(RealIPMiddleware)
r.Use(logger.Logger("router", log.StandardLogger())) r.Use(logger.Logger("router", log.StandardLogger()))
r.HandleFunc("/status", statusHandler) r.Get("/status", statusHandler)
r.HandleFunc("/mirrors", mirrorsHandler) r.Get("/mirrors", mirrorsHandler)
r.HandleFunc("/reload", reloadHandler) r.Post("/reload", reloadHandler)
r.HandleFunc("/dl_map", dlMapHandler) r.Get("/dl_map", dlMapHandler)
r.Handle("/metrics", promhttp.Handler()) r.Get("/metrics", promhttp.Handler().ServeHTTP)
r.HandleFunc("/", redirectHandler)
r.NotFound(redirectHandler)
go http.ListenAndServe(viper.GetString("bind"), r) go http.ListenAndServe(viper.GetString("bind"), r)

View File

@ -29,7 +29,9 @@ func RealIPMiddleware(f http.Handler) http.Handler {
return return
} }
if !net.ParseIP(host).IsPrivate() { netIP := net.ParseIP(host)
if !netIP.IsLoopback() && !netIP.IsPrivate() {
f.ServeHTTP(w, r) f.ServeHTTP(w, r)
return return
} }