Problem:
- I'm fowarding to a HTTPS address.
- I want to see why removing
req.Host = req.URL.Host
causes it to fail. Instead of returning{"Code":"OBRI.FR.Request.Invalid","Id":"c37baec213dd1227","Message":"An error happened when parsing the request arguments","Errors":[{"ErrorCode":"UK.OBIE.Header.Missing","Message":"Missing request header 'x-fapi-financial-id' for method parameter of type String","Url":"https://docs.ob.forgerock.financial/errors#UK.OBIE.Header.Missing"}]}
it returns a404
. - I want to trace the call the proxy returned from
httputil. NewSingleHostReverseProxy
is making when I uncommment the linereq.Host = req.URL.Host
.
Given a request as such:
$ curl http://localhost:8989/open-banking/v2.0/accounts
And the code below (main.go
):
package main
import (
"log"
"net/http"
"net/http/httputil"
"net/url"
)
func main() {
target, err := url.Parse("https://rs.aspsp.ob.forgerock.financial:443")
log.Printf("forwarding to -> %s%s
", target.Scheme, target.Host)
if err != nil {
log.Fatal(err)
}
proxy := httputil.NewSingleHostReverseProxy(target)
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
// https://stackoverflow.com/questions/38016477/reverse-proxy-does-not-work
// https://forum.golangbridge.org/t/explain-how-reverse-proxy-work/6492/7
// https://stackoverflow.com/questions/34745654/golang-reverseproxy-with-apache2-sni-hostname-error
req.Host = req.URL.Host // if you remove this line the request will fail... I want to debug why.
proxy.ServeHTTP(w, req)
})
err = http.ListenAndServe(":8989", nil)
if err != nil {
panic(err)
}
}