forked from qdeconinck/mp-quic
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
71 lines (61 loc) · 1.28 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
package main
import (
"bytes"
"flag"
"io"
"log"
"net/http"
"os"
"sync"
quic "github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/h2quic"
"github.com/lucas-clemente/quic-go/internal/utils"
)
func main() {
verbose := flag.Bool("v", false, "verbose")
multipath := flag.Bool("m", false, "multipath")
output := flag.String("o", "", "logging output")
flag.Parse()
urls := flag.Args()
if *verbose {
utils.SetLogLevel(utils.LogLevelDebug)
} else {
utils.SetLogLevel(utils.LogLevelInfo)
}
utils.SetLogTimeFormat("")
if *output != "" {
logfile, err := os.Create(*output)
if err != nil {
panic(err)
}
defer logfile.Close()
log.SetOutput(logfile)
}
quicConfig := &quic.Config{
CreatePaths: *multipath,
}
hclient := &http.Client{
Transport: &h2quic.RoundTripper{QuicConfig: quicConfig},
}
var wg sync.WaitGroup
wg.Add(len(urls))
for _, addr := range urls {
utils.Infof("GET %s", addr)
go func(addr string) {
rsp, err := hclient.Get(addr)
if err != nil {
panic(err)
}
utils.Infof("Got response for %s: %#v", addr, rsp)
body := &bytes.Buffer{}
_, err = io.Copy(body, rsp.Body)
if err != nil {
panic(err)
}
utils.Infof("Request Body:")
utils.Infof("%s", body.Bytes())
wg.Done()
}(addr)
}
wg.Wait()
}