plaprox

Proxy for plausible.io scripts written in Go.
git clone git://vcs.sapka.me/plaprox
Log | Files | Refs | README | LICENSE

commit 7ec127eb314d617d74393c6efb846015d39e09c8
parent 12a246bb0d2f8cb577c43fb087647f00a7631ed8
Author: Michał M. Sapka <michal@sapka.me>
Date:   Fri, 14 Jul 2023 12:48:26 +0200

fix: disable forwarding headers

This breaks reading the request by browser. Seems to be unused.

Diffstat:
Mmain.go | 10+++++++---
Mmain_test.go | 3++-
2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/main.go b/main.go @@ -1,4 +1,4 @@ -//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || plan9 +//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || plan9p /* Copyright 2023 Michał Sapka (https://michal.sapka.me) @@ -71,14 +71,17 @@ func main() { // Proxies requests to Plausible.io and returns the response to the client func Proxy(w http.ResponseWriter, r *http.Request) { req, _ := http.NewRequest(r.Method, "https://"+PlausibleHost+r.URL.Path, r.Body) - + + /* + Forwarding headers breaks reading the returned file in browsers. Seems to be + not needed, so I'll just comment this logic out for key, values := range r.Header { req.Header.Del(key) for _, value := range values { req.Header.Add(key, value) } } - + */ resp, _ := Client.Do(req) defer resp.Body.Close() @@ -96,6 +99,7 @@ func Proxy(w http.ResponseWriter, r *http.Request) { } func serveProxy() { + http.HandleFunc("/js/script.js", Proxy) http.HandleFunc("/api/event", Proxy) diff --git a/main_test.go b/main_test.go @@ -31,10 +31,11 @@ func mockProxiedCall(url string, responseBody string, headers map[string][]strin if req.URL.Path != url { t.Errorf("Invalid url. Got: %q, want: %q", req.URL.Path, url) } + /* if fmt.Sprint(req.Header) != fmt.Sprint(headers) { t.Errorf("Invalid proxied headers. Got: %q, want: %q", req.Header, headers) - } + */ return &http.Response{ StatusCode: 200,