headers; they make a world of difference

This commit is contained in:
Michael Quigley 2022-07-21 12:46:49 -04:00
parent d471484f99
commit 7e39a99ade
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
2 changed files with 22 additions and 14 deletions

View File

@ -34,25 +34,29 @@ func Run(cfg *Config) error {
type handler struct{} type handler struct{}
func (self *handler) ServeHTTP(res http.ResponseWriter, req *http.Request) { func (self *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
logrus.Infof("handling request from [%v]", req.RemoteAddr) logrus.Infof("handling request from [%v]", r.RemoteAddr)
req.Host = "localhost:3000" r.Host = "localhost:3000"
req.URL.Host = "localhost:3000" r.URL.Host = "localhost:3000"
req.URL.Scheme = "http" r.URL.Scheme = "http"
req.RequestURI = "" r.RequestURI = ""
rRes, err := http.DefaultClient.Do(req) rr, err := http.DefaultClient.Do(r)
if err != nil { if err != nil {
res.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
_, _ = fmt.Fprint(res, err) _, _ = fmt.Fprint(w, err)
return 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 { if err != nil {
res.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
_, _ = fmt.Fprint(res, err) _, _ = fmt.Fprint(w, err)
return return
} }

View File

@ -43,14 +43,18 @@ func (self *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
r.RequestURI = "" r.RequestURI = ""
logrus.Warnf("request: %v", r) logrus.Warnf("request: %v", r)
pResp, err := client.Do(r) rr, err := client.Do(r)
if err != nil { if err != nil {
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
_, _ = fmt.Fprint(w, err) _, _ = fmt.Fprint(w, err)
return 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 { if err != nil {
panic(err) panic(err)
} }