From 7e39a99ade1fe94a02a5f7b8e58fca28046303b0 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Thu, 21 Jul 2022 12:46:49 -0400 Subject: [PATCH] headers; they make a world of difference --- http/http.go | 28 ++++++++++++++++------------ proxy/proxy.go | 8 ++++++-- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/http/http.go b/http/http.go index 0a200256..ae1296d8 100644 --- a/http/http.go +++ b/http/http.go @@ -34,25 +34,29 @@ func Run(cfg *Config) error { type handler struct{} -func (self *handler) ServeHTTP(res http.ResponseWriter, req *http.Request) { - logrus.Infof("handling request from [%v]", req.RemoteAddr) +func (self *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + logrus.Infof("handling request from [%v]", r.RemoteAddr) - req.Host = "localhost:3000" - req.URL.Host = "localhost:3000" - req.URL.Scheme = "http" - req.RequestURI = "" + r.Host = "localhost:3000" + r.URL.Host = "localhost:3000" + r.URL.Scheme = "http" + r.RequestURI = "" - rRes, err := http.DefaultClient.Do(req) + rr, err := http.DefaultClient.Do(r) if err != nil { - res.WriteHeader(http.StatusInternalServerError) - _, _ = fmt.Fprint(res, err) + w.WriteHeader(http.StatusInternalServerError) + _, _ = fmt.Fprint(w, err) return } - n, err := io.Copy(res, rRes.Body) + for k, v := range rr.Header { + w.Header().Add(k, v[0]) + } + + n, err := io.Copy(w, rr.Body) if err != nil { - res.WriteHeader(http.StatusInternalServerError) - _, _ = fmt.Fprint(res, err) + w.WriteHeader(http.StatusInternalServerError) + _, _ = fmt.Fprint(w, err) return } diff --git a/proxy/proxy.go b/proxy/proxy.go index a68affa0..9986015f 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -43,14 +43,18 @@ func (self *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { r.RequestURI = "" logrus.Warnf("request: %v", r) - pResp, err := client.Do(r) + rr, err := client.Do(r) if err != nil { w.WriteHeader(http.StatusInternalServerError) _, _ = fmt.Fprint(w, err) return } - n, err := io.Copy(w, pResp.Body) + for k, v := range rr.Header { + w.Header().Add(k, v[0]) + } + + n, err := io.Copy(w, rr.Body) if err != nil { panic(err) }