Skip to content

Commit

Permalink
dedupe Alt-Svc header values (#3461)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrobenolt committed Jun 28, 2022
1 parent 706a482 commit 98b2587
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion http3/server.go
Expand Up @@ -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{}{}
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions http3/server_test.go
Expand Up @@ -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() {
Expand Down

0 comments on commit 98b2587

Please sign in to comment.