@@ -41,17 +41,17 @@ func rootHandler(sleep time.Duration) http.HandlerFunc {
4141
4242func proxyHandler (target string ) http.HandlerFunc {
4343 return func (w http.ResponseWriter , req * http.Request ) {
44- // parse the url
45- url , _ := url .Parse (target )
44+ // parse the targetURL
45+ targetURL , _ := url .Parse (target )
4646
4747 // create the reverse proxy
48- proxy := httputil .NewSingleHostReverseProxy (url )
48+ proxy := httputil .NewSingleHostReverseProxy (targetURL )
4949
5050 // Update the headers to allow for SSL redirection
51- req .URL .Host = url .Host
52- req .URL .Scheme = url .Scheme
51+ req .URL .Host = targetURL .Host
52+ req .URL .Scheme = targetURL .Scheme
5353 req .Header .Set ("X-Forwarded-Host" , req .Header .Get ("Host" ))
54- req .Host = url .Host
54+ req .Host = targetURL .Host
5555
5656 // Note that ServeHttp is non blocking and uses a go routine under the hood
5757 proxy .ServeHTTP (w , req )
@@ -75,7 +75,7 @@ func logRequest(handler http.Handler) http.Handler {
7575 message := fmt .Sprintf ("Request:\n %s\n Response Code: %d\n Response:\n %s\n \n " , string (x ), rec .Code , rec .Body .String ())
7676 if rec .Code >= 500 {
7777 color .Error .Block (message )
78- } else if rec .Code >= 404 {
78+ } else if rec .Code >= 400 {
7979 color .Warn .Block (message )
8080 } else if rec .Code >= 200 {
8181 color .Info .Block (message )
@@ -85,6 +85,6 @@ func logRequest(handler http.Handler) http.Handler {
8585 w .Header ()[k ] = v
8686 }
8787 w .WriteHeader (rec .Code )
88- rec .Body .WriteTo (w )
88+ _ , _ = rec .Body .WriteTo (w )
8989 })
9090}
0 commit comments