forked from valyala/fasthttp
-
Notifications
You must be signed in to change notification settings - Fork 12
/
client_example_test.go
39 lines (33 loc) · 1.04 KB
/
client_example_test.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
package fasthttp_test
import (
"log"
"github.com/erikdubbelboer/fasthttp"
)
func ExampleHostClient() {
// Perpare a client, which fetches webpages via HTTP proxy listening
// on the localhost:8080.
c := &fasthttp.HostClient{
Addr: "localhost:8080",
}
// Fetch google page via local proxy.
statusCode, body, err := c.Get(nil, "http://google.com/foo/bar")
if err != nil {
log.Fatalf("Error when loading google page through local proxy: %s", err)
}
if statusCode != fasthttp.StatusOK {
log.Fatalf("Unexpected status code: %d. Expecting %d", statusCode, fasthttp.StatusOK)
}
useResponseBody(body)
// Fetch foobar page via local proxy. Reuse body buffer.
statusCode, body, err = c.Get(body, "http://foobar.com/google/com")
if err != nil {
log.Fatalf("Error when loading foobar page through local proxy: %s", err)
}
if statusCode != fasthttp.StatusOK {
log.Fatalf("Unexpected status code: %d. Expecting %d", statusCode, fasthttp.StatusOK)
}
useResponseBody(body)
}
func useResponseBody(body []byte) {
// Do something with body :)
}