From e4f404d8d6a6198131a8bc7e8eaea70f7869d3ab Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Tue, 12 Mar 2024 09:47:38 +0100 Subject: [PATCH] Remove unused StripPrefix Not used since 8b3fbdb64a522d406d182bda5550d7c4964e0098 --- admin/main.go | 42 ------------------------------------------ dashboard/main.go | 42 ------------------------------------------ qa/main.go | 43 ------------------------------------------- 3 files changed, 127 deletions(-) diff --git a/admin/main.go b/admin/main.go index 523d8dd5..f793d5eb 100644 --- a/admin/main.go +++ b/admin/main.go @@ -5,13 +5,11 @@ import ( "io/fs" "log" "net/http" - "net/url" "os" "os/signal" "path" "path/filepath" "strconv" - "strings" "syscall" "srs.epita.fr/fic-server/admin/api" @@ -22,46 +20,6 @@ import ( "srs.epita.fr/fic-server/settings" ) -type ResponseWriterPrefix struct { - real http.ResponseWriter - prefix string -} - -func (r ResponseWriterPrefix) Header() http.Header { - return r.real.Header() -} - -func (r ResponseWriterPrefix) WriteHeader(s int) { - if v, exists := r.real.Header()["Location"]; exists { - r.real.Header().Set("Location", r.prefix+v[0]) - } - r.real.WriteHeader(s) -} - -func (r ResponseWriterPrefix) Write(z []byte) (int, error) { - return r.real.Write(z) -} - -func StripPrefix(prefix string, h http.Handler) http.Handler { - if prefix == "" { - return h - } - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if prefix != "/" && r.URL.Path == "/" { - http.Redirect(w, r, prefix+"/", http.StatusFound) - } else if p := strings.TrimPrefix(r.URL.Path, prefix); len(p) < len(r.URL.Path) { - r2 := new(http.Request) - *r2 = *r - r2.URL = new(url.URL) - *r2.URL = *r.URL - r2.URL.Path = p - h.ServeHTTP(ResponseWriterPrefix{w, prefix}, r2) - } else { - h.ServeHTTP(w, r) - } - }) -} - func main() { var err error bind := "127.0.0.1:8081" diff --git a/dashboard/main.go b/dashboard/main.go index 69ec447a..4c6de9e0 100644 --- a/dashboard/main.go +++ b/dashboard/main.go @@ -5,12 +5,10 @@ import ( "io/fs" "log" "net/http" - "net/url" "os" "os/signal" "path" "path/filepath" - "strings" "syscall" "srs.epita.fr/fic-server/libfic" @@ -20,46 +18,6 @@ import ( var DashboardDir string var TeamsDir string -type ResponseWriterPrefix struct { - real http.ResponseWriter - prefix string -} - -func (r ResponseWriterPrefix) Header() http.Header { - return r.real.Header() -} - -func (r ResponseWriterPrefix) WriteHeader(s int) { - if v, exists := r.real.Header()["Location"]; exists { - r.real.Header().Set("Location", r.prefix+v[0]) - } - r.real.WriteHeader(s) -} - -func (r ResponseWriterPrefix) Write(z []byte) (int, error) { - return r.real.Write(z) -} - -func StripPrefix(prefix string, h http.Handler) http.Handler { - if prefix == "" { - return h - } - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if prefix != "/" && r.URL.Path == "/" { - http.Redirect(w, r, prefix+"/", http.StatusFound) - } else if p := strings.TrimPrefix(r.URL.Path, prefix); len(p) < len(r.URL.Path) { - r2 := new(http.Request) - *r2 = *r - r2.URL = new(url.URL) - *r2.URL = *r.URL - r2.URL.Path = p - h.ServeHTTP(ResponseWriterPrefix{w, prefix}, r2) - } else { - h.ServeHTTP(w, r) - } - }) -} - func main() { var baseURL string // Read paremeters from environment diff --git a/qa/main.go b/qa/main.go index 81ba9d4e..e894cf38 100644 --- a/qa/main.go +++ b/qa/main.go @@ -3,12 +3,9 @@ package main import ( "flag" "log" - "net/http" - "net/url" "os" "os/signal" "path" - "strings" "syscall" "srs.epita.fr/fic-server/libfic" @@ -16,46 +13,6 @@ import ( "srs.epita.fr/fic-server/settings" ) -type ResponseWriterPrefix struct { - real http.ResponseWriter - prefix string -} - -func (r ResponseWriterPrefix) Header() http.Header { - return r.real.Header() -} - -func (r ResponseWriterPrefix) WriteHeader(s int) { - if v, exists := r.real.Header()["Location"]; exists { - r.real.Header().Set("Location", r.prefix+v[0]) - } - r.real.WriteHeader(s) -} - -func (r ResponseWriterPrefix) Write(z []byte) (int, error) { - return r.real.Write(z) -} - -func StripPrefix(prefix string, h http.Handler) http.Handler { - if prefix == "" { - return h - } - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if prefix != "/" && r.URL.Path == "/" { - http.Redirect(w, r, prefix+"/", http.StatusFound) - } else if p := strings.TrimPrefix(r.URL.Path, prefix); len(p) < len(r.URL.Path) { - r2 := new(http.Request) - *r2 = *r - r2.URL = new(url.URL) - *r2.URL = *r.URL - r2.URL.Path = p - h.ServeHTTP(ResponseWriterPrefix{w, prefix}, r2) - } else { - h.ServeHTTP(w, r) - } - }) -} - func reloadSettings(config *settings.Settings) { api.ManagerUsers = config.DelegatedQA }