Fix bug that prevents custom user-agents

This commit is contained in:
Erik Dubbelboer
2018-08-17 15:57:45 +08:00
committed by Kirill Danshin
parent a58298a3a8
commit 5576019a85
2 changed files with 31 additions and 3 deletions
-3
View File
@@ -1079,9 +1079,6 @@ func (c *HostClient) doNonNilReqResp(req *Request, resp *Response) (bool, error)
}
bw := c.acquireWriter(conn)
err = req.Write(bw)
if len(userAgentOld) == 0 {
req.Header.userAgent = userAgentOld
}
if resetConnection {
req.Header.ResetConnectionClose()
+31
View File
@@ -17,6 +17,37 @@ import (
"github.com/valyala/fasthttp/fasthttputil"
)
func TestClientUserAgent(t *testing.T) {
ln := fasthttputil.NewInmemoryListener()
s := &Server{
Handler: func(ctx *RequestCtx) {
ctx.Write([]byte("response"))
},
}
go s.Serve(ln)
userAgent := "I'm not fasthttp"
c := &Client{
Name: userAgent,
Dial: func(addr string) (net.Conn, error) {
return ln.Dial()
},
}
req := AcquireRequest()
res := AcquireResponse()
req.SetRequestURI("http://do.not.worry?we.are.going.to.make.fasthttp.great.again")
err := c.Do(req, res)
if err != nil {
t.Fatal(err)
}
if ua := string(req.Header.UserAgent()); ua != userAgent {
t.Fatalf("User-Agent defers %s <> %s", ua, userAgent)
}
}
func TestClientDoWithCustomHeaders(t *testing.T) {
// make sure that the client sends all the request headers and body.
ln := fasthttputil.NewInmemoryListener()