forked from valyala/fasthttp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package fasthttp_test | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/valyala/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 :) | ||
} |