mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-17 16:26:47 +03:00
Fix bug that prevents custom user-agents
This commit is contained in:
committed by
Kirill Danshin
parent
a58298a3a8
commit
5576019a85
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user