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