Last active
June 7, 2016 04:48
-
-
Save messyidea/4c01dafb0facfa2c4d81522f3cb524db to your computer and use it in GitHub Desktop.
Revisions
-
messyidea revised this gist
Jun 7, 2016 . 1 changed file with 6 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,9 +9,10 @@ import ( "strings" ) func main() { target, _ := url.Parse("https://www.google.com") r := &httputil.ReverseProxy{ Director: func(req *http.Request) { req.URL.Scheme = target.Scheme @@ -27,7 +28,7 @@ func main() { } http.Handle("/", r) http.ListenAndServeTLS(":443", "public.crt", "private.pem", nil) } func singleJoiningSlash(a, b string) string { @@ -41,3 +42,6 @@ func singleJoiningSlash(a, b string) string { } return a + b } // openssl genrsa -out private.pem 2048 // openssl req -new -x509 -sha256 -key private.pem -out public.crt -days 99999 -
horsley created this gist
Oct 4, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ // grproxy project main.go package main import ( "net/http" "net/http/httputil" "net/url" "strings" ) func main() { target, _ := url.Parse("http://www.google.com") r := &httputil.ReverseProxy{ Director: func(req *http.Request) { req.URL.Scheme = target.Scheme req.URL.Host = target.Host req.Host = target.Host //这才是关键 req.URL.Path = singleJoiningSlash(target.Path, req.URL.Path) if target.RawQuery == "" || req.URL.RawQuery == "" { req.URL.RawQuery = target.RawQuery + req.URL.RawQuery } else { req.URL.RawQuery = target.RawQuery + "&" + req.URL.RawQuery } }, } http.Handle("/", r) http.ListenAndServe(":80", nil) } func singleJoiningSlash(a, b string) string { aslash := strings.HasSuffix(a, "/") bslash := strings.HasPrefix(b, "/") switch { case aslash && bslash: return a + b[1:] case !aslash && !bslash: return a + "/" + b } return a + b }