File: example_test.go

package info (click to toggle)
golang-github-mattn-go-ieproxy 0.0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 192 kB
  • sloc: makefile: 2
file content (37 lines) | stat: -rw-r--r-- 746 bytes parent folder | download | duplicates (2)
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: ...
}