Skip to content

Commit 17d1039

Browse files
grpc: Export header list sizes in DialOption and ServerOption (grpc#7033)
1 parent ba1bf9e commit 17d1039

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

default_dial_option_server_option_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,16 @@ func (s) TestJoinServerOption(t *testing.T) {
132132
t.Fatalf("Unexpected s.opts.initialWindowSize: %d != %d", s.opts.initialWindowSize, initialWindowSize)
133133
}
134134
}
135+
136+
// funcTestHeaderListSizeDialOptionServerOption tests
137+
func (s) TestHeaderListSizeDialOptionServerOption(t *testing.T) {
138+
const maxHeaderListSize uint32 = 998765
139+
clientHeaderListSize := WithMaxHeaderListSize(maxHeaderListSize)
140+
if clientHeaderListSize.(MaxHeaderListSizeDialOption).MaxHeaderListSize != maxHeaderListSize {
141+
t.Fatalf("Unexpected s.opts.MaxHeaderListSizeDialOption.MaxHeaderListSize: %d != %d", clientHeaderListSize, maxHeaderListSize)
142+
}
143+
serverHeaderListSize := MaxHeaderListSize(maxHeaderListSize)
144+
if serverHeaderListSize.(MaxHeaderListSizeServerOption).MaxHeaderListSize != maxHeaderListSize {
145+
t.Fatalf("Unexpected s.opts.MaxHeaderListSizeDialOption.MaxHeaderListSize: %d != %d", serverHeaderListSize, maxHeaderListSize)
146+
}
147+
}

dialoptions.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -601,12 +601,22 @@ func WithDisableRetry() DialOption {
601601
})
602602
}
603603

604+
// MaxHeaderListSizeDialOption is a DialOption that specifies the maximum
605+
// (uncompressed) size of header list that the client is prepared to accept.
606+
type MaxHeaderListSizeDialOption struct {
607+
MaxHeaderListSize uint32
608+
}
609+
610+
func (o MaxHeaderListSizeDialOption) apply(do *dialOptions) {
611+
do.copts.MaxHeaderListSize = &o.MaxHeaderListSize
612+
}
613+
604614
// WithMaxHeaderListSize returns a DialOption that specifies the maximum
605615
// (uncompressed) size of header list that the client is prepared to accept.
606616
func WithMaxHeaderListSize(s uint32) DialOption {
607-
return newFuncDialOption(func(o *dialOptions) {
608-
o.copts.MaxHeaderListSize = &s
609-
})
617+
return MaxHeaderListSizeDialOption{
618+
MaxHeaderListSize: s,
619+
}
610620
}
611621

612622
// WithDisableHealthCheck disables the LB channel health checking for all

server.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,12 +527,22 @@ func ConnectionTimeout(d time.Duration) ServerOption {
527527
})
528528
}
529529

530+
// MaxHeaderListSizeServerOption is a ServerOption that sets the max
531+
// (uncompressed) size of header list that the server is prepared to accept.
532+
type MaxHeaderListSizeServerOption struct {
533+
MaxHeaderListSize uint32
534+
}
535+
536+
func (o MaxHeaderListSizeServerOption) apply(so *serverOptions) {
537+
so.maxHeaderListSize = &o.MaxHeaderListSize
538+
}
539+
530540
// MaxHeaderListSize returns a ServerOption that sets the max (uncompressed) size
531541
// of header list that the server is prepared to accept.
532542
func MaxHeaderListSize(s uint32) ServerOption {
533-
return newFuncServerOption(func(o *serverOptions) {
534-
o.maxHeaderListSize = &s
535-
})
543+
return MaxHeaderListSizeServerOption{
544+
MaxHeaderListSize: s,
545+
}
536546
}
537547

538548
// HeaderTableSize returns a ServerOption that sets the size of dynamic

0 commit comments

Comments
 (0)