Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dedupe Alt-Svc header values #3461

Merged
merged 1 commit into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion http3/server.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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