aboutsummaryrefslogtreecommitdiff
path: root/client_test.go
diff options
context:
space:
mode:
authorGravatar kiyon <kiyonlin@163.com> 2021-03-16 00:46:16 +0800
committerGravatar GitHub <noreply@github.com> 2021-03-15 17:46:16 +0100
commit02e0722fb73c6237818b8e5af55957eb919a7334 (patch)
tree772a96de9fa98d36232d7070ebc5690ca0f874b8 /client_test.go
parentformat err info (#989) (diff)
downloadfasthttp-02e0722fb73c6237818b8e5af55957eb919a7334.tar.gz
fasthttp-02e0722fb73c6237818b8e5af55957eb919a7334.tar.bz2
fasthttp-02e0722fb73c6237818b8e5af55957eb919a7334.zip
Add PipelineClient name (#994)
* Improve documentation about DelClientCookie which related with #951. * Add pipeline name
Diffstat (limited to 'client_test.go')
-rw-r--r--client_test.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/client_test.go b/client_test.go
index 48b5b85..2fb708b 100644
--- a/client_test.go
+++ b/client_test.go
@@ -68,6 +68,56 @@ func TestCloseIdleConnections(t *testing.T) {
}
}
+func TestPipelineClientSetUserAgent(t *testing.T) {
+ t.Parallel()
+
+ testPipelineClientSetUserAgent(t, 0)
+}
+
+func TestPipelineClientSetUserAgentTimeout(t *testing.T) {
+ t.Parallel()
+
+ testPipelineClientSetUserAgent(t, time.Second)
+}
+
+func testPipelineClientSetUserAgent(t *testing.T, timeout time.Duration) {
+ ln := fasthttputil.NewInmemoryListener()
+
+ userAgentSeen := ""
+ s := &Server{
+ Handler: func(ctx *RequestCtx) {
+ userAgentSeen = string(ctx.UserAgent())
+ },
+ }
+ go s.Serve(ln) //nolint:errcheck
+
+ userAgent := "I'm not fasthttp"
+ c := &HostClient{
+ Name: userAgent,
+ Dial: func(addr string) (net.Conn, error) {
+ return ln.Dial()
+ },
+ }
+ req := AcquireRequest()
+ res := AcquireResponse()
+
+ req.SetRequestURI("http://example.com")
+
+ var err error
+ if timeout <= 0 {
+ err = c.Do(req, res)
+ } else {
+ err = c.DoTimeout(req, res, timeout)
+ }
+
+ if err != nil {
+ t.Fatal(err)
+ }
+ if userAgentSeen != userAgent {
+ t.Fatalf("User-Agent defers %q != %q", userAgentSeen, userAgent)
+ }
+}
+
func TestPipelineClientIssue832(t *testing.T) {
t.Parallel()