Last active
February 19, 2021 06:06
-
-
Save Apurer/35db3147cd192bb8aebed5ca4e05b278 to your computer and use it in GitHub Desktop.
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 characters
| package main | |
| import ( | |
| "crypto/tls" | |
| "fmt" | |
| "net" | |
| "time" | |
| "io/ioutil" | |
| "log" | |
| "net/http" | |
| "net/http/httptest" | |
| "net/http/httputil" | |
| "net/url" | |
| ) | |
| func main() { | |
| rpURL, err := url.Parse("https://35.x.x.x/") | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| director := func(req *http.Request) { | |
| req.URL.Scheme = rpURL.Scheme | |
| req.URL.Host = rpURL.Host | |
| } | |
| transport := &http.Transport{ | |
| Proxy: http.ProxyFromEnvironment, | |
| Dial: (&net.Dialer{ | |
| Timeout: 30 * time.Second, | |
| KeepAlive: 30 * time.Second, | |
| }).Dial, | |
| TLSHandshakeTimeout: 10 * time.Second, | |
| TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, | |
| } | |
| reverseProxy := httptest.NewServer(&httputil.ReverseProxy{Director: director, Transport: transport}) | |
| defer reverseProxy.Close() | |
| client := &http.Client{} | |
| r, _ := http.NewRequest(http.MethodGet, reverseProxy.URL, nil) | |
| sum := "127.0.0.1" | |
| for i := 0; i < 5; i++ { | |
| sum += "," + sum | |
| } | |
| r.Header.Add("X-Forwarded-For", sum) | |
| resp, _ := client.Do(r) | |
| fmt.Println(resp.Status) | |
| b, err := ioutil.ReadAll(resp.Body) | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| fmt.Printf("%s", b) | |
| } |
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 characters
| package main | |
| import ( | |
| "crypto/tls" | |
| "fmt" | |
| "net" | |
| "time" | |
| "io/ioutil" | |
| "log" | |
| "net/http" | |
| "net/http/httptest" | |
| "net/http/httputil" | |
| "net/url" | |
| ) | |
| func main() { | |
| rpURL, err := url.Parse("https://35.x.x.x/") | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| director := func(req *http.Request) { | |
| req.URL.Scheme = rpURL.Scheme | |
| req.URL.Host = rpURL.Host | |
| } | |
| transport := &http.Transport{ | |
| Proxy: http.ProxyFromEnvironment, | |
| Dial: (&net.Dialer{ | |
| Timeout: 30 * time.Second, | |
| KeepAlive: 30 * time.Second, | |
| }).Dial, | |
| TLSHandshakeTimeout: 10 * time.Second, | |
| TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, | |
| } | |
| reverseProxy := httptest.NewServer(&httputil.ReverseProxy{Director: director, Transport: transport}) | |
| defer reverseProxy.Close() | |
| resp, err := http.Get(reverseProxy.URL) | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| b, err := ioutil.ReadAll(resp.Body) | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| fmt.Printf("%s", b) | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Value: https://35.x.x.x/ has to be replaced with ingress external IP.