-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathh2rquic.go
72 lines (56 loc) · 1.18 KB
/
h2rquic.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
package main
import (
"crypto/tls"
"fmt"
"io"
"net/http"
"net/http/httputil"
"time"
quic "github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/h2quic"
)
func h2OverQUIC(network, local, addr, rawurl string,
tlsCfg *tls.Config, cfg *quic.Config,
buffer []byte, dst io.Writer) {
roundTripper := &h2quic.RoundTripper{
TLSClientConfig: tlsCfg,
QuicConfig: cfg,
Dial: dialFunc(local, addr),
}
defer roundTripper.Close()
client := &http.Client{
Transport: roundTripper,
}
dial := time.Now()
req, err := http.NewRequest("GET", rawurl, nil)
if err != nil {
fmt.Println(err)
return
}
data, err := httputil.DumpRequestOut(req, true)
if err != nil {
fmt.Println(err)
return
}
fmt.Println()
fmt.Println(string(data))
resp, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
readresp := time.Now()
fmt.Println("recvresp:", readresp.Sub(dial).String())
fmt.Println()
rp, err := DumpResponse(resp)
fmt.Println(string(rp))
if err != nil {
fmt.Println(err)
}
if _, err := io.CopyBuffer(dst, resp.Body, buffer); err != nil {
fmt.Println(err)
}
if resp != nil && resp.Body != nil {
resp.Body.Close()
}
}