From 383ff6b6069e757e17cccd5f36dfffec3ae22c8a Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sun, 10 Nov 2024 11:19:53 -0300 Subject: src/glaze.go: Add simplistic -X redirect implementation --- src/glaze.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/glaze.go b/src/glaze.go index 5ab635f..2644211 100644 --- a/src/glaze.go +++ b/src/glaze.go @@ -261,7 +261,7 @@ func handlerFor(path string) http.HandlerFunc { }) } -func (i *patternPath) String() string { +func (_ *patternPath) String() string { return "" } @@ -286,17 +286,29 @@ func (_ *patternPath) Set(value string) error { func parseArgs(args []string) string { var pat patternPath + redirect := false + fs := flag.NewFlagSet(args[0], flag.ExitOnError) - fs.Var(&pat, "P", "") + fs.Var(&pat, "P", "FIXME") + fs.BoolVar(&redirect, "X", false, "FIXME") fs.Parse(args[1:]) if fs.NArg() != 1 { fmt.Fprintf( os.Stderr, - "Usage: %s [ -P PATTERN:PATH ]... LISTEN.socket\n", + "Usage: %s ([ -P PATTERN:PATH ]... | -X) " + + "LISTEN.socket\n", args[0], ) os.Exit(2) } + + if redirect { + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + target := "https://" + r.Host + r.RequestURI + http.Redirect(w, r, target, http.StatusMovedPermanently) + }) + } + return fs.Arg(0) } -- cgit v1.2.3