@@ -556,6 +556,19 @@ func (t *http2Client) createHeaderFields(ctx context.Context, callHdr *CallHdr)
556
556
// Make the slice of certain predictable size to reduce allocations made by append.
557
557
hfLen := 7 // :method, :scheme, :path, :authority, content-type, user-agent, te
558
558
hfLen += len (authData ) + len (callAuthData )
559
+ registeredCompressors := t .registeredCompressors
560
+ if callHdr .PreviousAttempts > 0 {
561
+ hfLen ++
562
+ }
563
+ if callHdr .SendCompress != "" {
564
+ hfLen ++
565
+ }
566
+ if registeredCompressors != "" {
567
+ hfLen ++
568
+ }
569
+ if _ , ok := ctx .Deadline (); ok {
570
+ hfLen ++
571
+ }
559
572
headerFields := make ([]hpack.HeaderField , 0 , hfLen )
560
573
headerFields = append (headerFields , hpack.HeaderField {Name : ":method" , Value : "POST" })
561
574
headerFields = append (headerFields , hpack.HeaderField {Name : ":scheme" , Value : t .scheme })
@@ -568,7 +581,6 @@ func (t *http2Client) createHeaderFields(ctx context.Context, callHdr *CallHdr)
568
581
headerFields = append (headerFields , hpack.HeaderField {Name : "grpc-previous-rpc-attempts" , Value : strconv .Itoa (callHdr .PreviousAttempts )})
569
582
}
570
583
571
- registeredCompressors := t .registeredCompressors
572
584
if callHdr .SendCompress != "" {
573
585
headerFields = append (headerFields , hpack.HeaderField {Name : "grpc-encoding" , Value : callHdr .SendCompress })
574
586
// Include the outgoing compressor name when compressor is not registered
0 commit comments