Browse Source

Update httpsify.go

Mohammed Al Ashaal 8 years ago
parent
commit
27a1197c38
1 changed files with 7 additions and 1 deletions
  1. 7 1
      httpsify.go

+ 7 - 1
httpsify.go

@@ -58,6 +58,12 @@ func main() {
 	}
 	log.Fatal(http.Serve(listener, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 		defer r.Body.Close()
+		tr := &http.Transport{
+			CheckRedirect: func(req *http.Request, via []*http.Request) error {
+				return http.ErrUseLastResponse
+		    	},
+		}
+		client := &http.Client{Transport: tr}
 		req, err := http.NewRequest(r.Method, *backend + r.URL.RequestURI(), r.Body)
 		if err != nil {
 			http.Error(w, http.StatusText(504), 504)
@@ -78,7 +84,7 @@ func main() {
 		req.Header.Set("X-Forwarded-Proto", "https")
 		req.Header.Set("X-Forwarded-Host", r.Host)
 		req.Header.Set("X-Forwarded-Port", *port)
-		res, err := http.DefaultClient.Do(req)
+		res, err := client.Do(req)
 		if err != nil {
 			http.Error(w, http.StatusText(504), 504)
 			return