]> Sergey Matveev's repositories - godlighty.git/commitdiff
Safer query passing
authorSergey Matveev <stargrave@stargrave.org>
Fri, 17 Feb 2023 14:47:19 +0000 (17:47 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 17 Feb 2023 14:47:30 +0000 (17:47 +0300)
rc/example.cfg/proxied-host.go

index 0af56cc8b146d9b0596aba19df1c0125b5e32721..610379d034c36e8c3c7ed9dc7e2efa9ce9d69450 100644 (file)
@@ -6,6 +6,7 @@ import (
        "fmt"
        "io"
        "net/http"
+       "net/url"
 
        "go.stargrave.org/godlighty"
 )
@@ -15,10 +16,13 @@ func init() {
        godlighty.Hosts[host] = &godlighty.HostCfg{
                Hooks: []godlighty.Hook{
                        func(w http.ResponseWriter, r *http.Request) bool {
+                               var err error
+                               if r.URL, err = url.ParseRequestURI(r.RequestURI); err != nil {
+                                       panic(err)
+                               }
                                r.URL.Scheme = "http"
                                r.URL.Host = "[dead::beaf]"
                                r.RequestURI = ""
-                               r.Host = host
                                resp, err := http.DefaultClient.Do(r)
                                if err != nil {
                                        fmt.Printf("%s %s \"%s %+q %s\" %d \"%s\" \"%s\"\n",