...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package httpchaos
17
18 import (
19 "fmt"
20 "net/http"
21 "strings"
22 "time"
23 )
24
25 const SECRET = "Secret"
26
27 type HTTPE2EClient struct {
28 IP string
29 C *http.Client
30 }
31
32 func getPodHttp(c HTTPE2EClient, port uint16, secret, body string) (*http.Response, error) {
33 request, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://%s:%d/http", c.IP, port), strings.NewReader(body))
34 if err != nil {
35 return nil, err
36 }
37 request.Header.Set(SECRET, secret)
38 client := &http.Client{
39 Transport: &http.Transport{},
40 }
41 resp, err := client.Do(request)
42 return resp, err
43 }
44
45 func getPodHttpNoSecret(c HTTPE2EClient, port uint16) (*http.Response, error) {
46 return getPodHttp(c, port, "", "")
47 }
48
49 func getPodHttpDefaultSecret(c HTTPE2EClient, port uint16, body string) (*http.Response, error) {
50 return getPodHttp(c, port, "foo", body)
51 }
52
53 func getPodHttpNoBody(c HTTPE2EClient, port uint16) (*http.Response, error) {
54 return getPodHttpDefaultSecret(c, port, "")
55 }
56
57
58 func getPodHttpDelay(c HTTPE2EClient, port uint16) (*http.Response, time.Duration, error) {
59 start := time.Now()
60 resp, err := getPodHttpNoBody(c, port)
61 if err != nil {
62 return nil, 0, err
63 }
64
65 return resp, time.Now().Sub(start), nil
66 }
67