Skip to content

Commit

Permalink
reduce dialer header allocs
Browse files Browse the repository at this point in the history
  • Loading branch information
phuslu committed Oct 27, 2024
1 parent 63a7059 commit ec6b7f8
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions client_dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,17 @@ func (d *HTTPDialer) DialContext(ctx context.Context, network, addr string) (net
c := httpconnpool.Get().(*httpConn)
c.dialer = d
c.ctx = ctx
c.req.Body = nil
c.req.URL = d.Endpoint
c.req.Host = d.Endpoint.Host
if d.Header != nil {
c.req.Header = d.Header
if c.req.Header == nil {
if d.Header != nil {
c.req.Header = d.Header
} else {
c.req.Header = httpconnheader
}
c.req.URL = d.Endpoint
c.req.Host = d.Endpoint.Host
}
c.reader.B = nil
c.writer.B = c.writer.B[:0]
c.reader.B = nil
c.resp = nil
return c, nil
}
Expand Down Expand Up @@ -283,15 +286,16 @@ var httpctxoffset = func() uintptr {
panic("unsupported go version, please upgrade fastdns")
}()

var httpconnheader = http.Header{
"content-type": {"application/dns-message"},
"user-agent": {"fastdns/1.0"},
}

var httpconnpool = sync.Pool{
New: func() any {
return &httpConn{
req: &http.Request{
Method: http.MethodPost,
Header: http.Header{
"content-type": {"application/dns-message"},
"user-agent": {"fastdns/1.0"},
},
},
reader: new(bufferreader),
writer: new(bufferwriter),
Expand Down

0 comments on commit ec6b7f8

Please sign in to comment.