github.com/gospider007/requests@v0.0.0-20240506025355-c73d46169a23/test/proxy_test.go (about) 1 package main 2 3 import ( 4 "context" 5 "net/url" 6 "testing" 7 8 "github.com/gospider007/requests" 9 ) 10 11 func TestProxy(t *testing.T) { 12 resp, err := requests.Get(nil, "https://httpbin.org/anything", requests.RequestOption{ 13 Proxy: "", //set proxy,ex:"http://127.0.0.1:8080","https://127.0.0.1:8080","socks5://127.0.0.1:8080" 14 }) 15 if err != nil { 16 t.Error(err) 17 } 18 if resp.StatusCode() != 200 { 19 t.Error("status code is not 200") 20 } 21 } 22 func TestGetProxy(t *testing.T) { 23 session, _ := requests.NewClient(nil, requests.ClientOption{ 24 GetProxy: func(ctx context.Context, url *url.URL) (string, error) { //Penalty when creating a new connection 25 proxy := "" //set proxy,ex:"http://127.0.0.1:8080","https://127.0.0.1:8080","socks5://127.0.0.1:8080" 26 return proxy, nil 27 }, 28 }) 29 resp, err := session.Get(nil, "https://httpbin.org/anything") 30 if err != nil { 31 t.Error(err) 32 } 33 if resp.StatusCode() != 200 { 34 t.Error("status code is not 200") 35 } 36 }