dedupe Alt-Svc header values (#3461)

This commit is contained in:
Matt Robenolt 2022-06-28 00:58:44 -07:00 committed by GitHub
parent 706a482340
commit 98b25879e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View file

@ -325,10 +325,16 @@ func (s *Server) generateAltSvcHeader() {
if s.QuicConfig != nil && len(s.QuicConfig.Versions) > 0 {
supportedVersions = s.QuicConfig.Versions
}
// keep track of which have been seen so we don't yield duplicate values
seen := make(map[string]struct{}, len(supportedVersions))
var versionStrings []string
for _, version := range supportedVersions {
if v := versionToALPN(version); len(v) > 0 {
versionStrings = append(versionStrings, v)
if _, ok := seen[v]; !ok {
versionStrings = append(versionStrings, v)
seen[v] = struct{}{}
}
}
}

View file

@ -893,6 +893,14 @@ var _ = Describe("Server", func() {
removeListener(&ln2)
checkSetHeaderError()
})
It("doesn't duplicate Alt-Svc values", func() {
s.QuicConfig.Versions = []quic.VersionNumber{quic.Version1, quic.Version1}
addListener(":443", &ln1)
checkSetHeaders(Equal(http.Header{"Alt-Svc": {`h3=":443"; ma=2592000`}}))
removeListener(&ln1)
checkSetHeaderError()
})
})
It("errors when ListenAndServe is called with s.TLSConfig nil", func() {