forked from mattn/go-ieproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
37 lines (32 loc) · 746 Bytes
/
example_test.go
File metadata and controls
37 lines (32 loc) · 746 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package ieproxy
import (
"fmt"
"net/http"
"os"
)
func init() {
OverrideEnvWithStaticProxy()
http.DefaultTransport.(*http.Transport).Proxy = http.ProxyFromEnvironment
}
func Example() {
fmt.Println("== Proxy configuration ==")
for _, name := range []string{"http_proxy", "https_proxy", "no_proxy"} {
fmt.Println(name + ": " + os.Getenv(name))
}
fmt.Println("== Proxy test ==")
req, err := http.NewRequest("GET", "https://golang.org/", nil)
if err != nil {
panic(err)
}
url, err := http.DefaultTransport.(*http.Transport).Proxy(req)
if err != nil {
panic(err)
}
if url != nil {
fmt.Println("PROXY " + url.String())
} else {
fmt.Println("DIRECT")
}
// Coming output: == Proxy configuration ==
// http_proxy: ...
}