forked from quic-go/quic-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
84 lines (75 loc) · 1.65 KB
/
main.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"bytes"
"crypto/x509"
"flag"
"io"
"log"
"net/http"
"os"
"sync"
tls "github.com/Psiphon-Labs/psiphon-tls"
"github.com/Psiphon-Labs/quic-go"
"github.com/Psiphon-Labs/quic-go/http3"
"github.com/Psiphon-Labs/quic-go/internal/testdata"
"github.com/Psiphon-Labs/quic-go/qlog"
)
func main() {
quiet := flag.Bool("q", false, "don't print the data")
keyLogFile := flag.String("keylog", "", "key log file")
insecure := flag.Bool("insecure", false, "skip certificate verification")
flag.Parse()
urls := flag.Args()
var keyLog io.Writer
if len(*keyLogFile) > 0 {
f, err := os.Create(*keyLogFile)
if err != nil {
log.Fatal(err)
}
defer f.Close()
keyLog = f
}
pool, err := x509.SystemCertPool()
if err != nil {
log.Fatal(err)
}
testdata.AddRootCA(pool)
roundTripper := &http3.RoundTripper{
TLSClientConfig: &tls.Config{
RootCAs: pool,
InsecureSkipVerify: *insecure,
KeyLogWriter: keyLog,
},
QuicConfig: &quic.Config{
Tracer: qlog.DefaultTracer,
},
}
defer roundTripper.Close()
hclient := &http.Client{
Transport: roundTripper,
}
var wg sync.WaitGroup
wg.Add(len(urls))
for _, addr := range urls {
log.Printf("GET %s", addr)
go func(addr string) {
rsp, err := hclient.Get(addr)
if err != nil {
log.Fatal(err)
}
log.Printf("Got response for %s: %#v", addr, rsp)
body := &bytes.Buffer{}
_, err = io.Copy(body, rsp.Body)
if err != nil {
log.Fatal(err)
}
if *quiet {
log.Printf("Response Body: %d bytes", body.Len())
} else {
log.Printf("Response Body (%d bytes):\n%s", body.Len(), body.Bytes())
}
wg.Done()
}(addr)
}
wg.Wait()
}