-
Notifications
You must be signed in to change notification settings - Fork 77
/
inspect.go
52 lines (42 loc) · 1.07 KB
/
inspect.go
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"context"
"crypto/tls"
"fmt"
"net/http"
"os"
"golang.org/x/net/http2"
)
func checkErr(err error, msg string) {
if err == nil {
return
}
fmt.Printf("ERROR: %s: %s\n", msg, err)
os.Exit(1)
}
func roundTripExample() {
req, err := http.NewRequestWithContext(context.Background(), "GET", os.Getenv("TARGET_URL")+"/pingrt", nil)
checkErr(err, "during new request")
tr := &http2.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
resp, err := tr.RoundTrip(req)
checkErr(err, "during roundtrip")
if err == nil {
fmt.Printf("RoundTrip Proto: %d\n", resp.ProtoMajor)
}
}
func main() {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %v, http: %v\n", r.URL.Path, r.TLS == nil)
})
server := &http.Server{
Addr: "0.0.0.0:8080",
Handler: handler,
}
err := http2.ConfigureServer(server, nil)
checkErr(err, "configuring server")
roundTripExample()
fmt.Printf("Listening [0.0.0.0:8080]...\n")
checkErr(server.ListenAndServeTLS("cert.pem", "key.pem"), "while listening")
}