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{}
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
}

View File

@ -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)
}