Skip to content

refactor: Change header keys to be canonical - #3389

Merged
gmlewis merged 1 commit into
google:masterfrom
alexandear-org:refactor/canonical-headers
Dec 16, 2024
Merged

refactor: Change header keys to be canonical#3389
gmlewis merged 1 commit into
google:masterfrom
alexandear-org:refactor/canonical-headers

Conversation

@alexandear

Copy link
Copy Markdown
Contributor

The PR enables the canonicalheader linter and changes header key strings to be in canonical form.

This is needed because canonical header keys don't need to be converted to a canonical form via http.CanonicalHeaderKey, leading to fewer allocations when adding, setting or getting a header.

Benchmarks
funcBenchmarkCanonical(b*testing.B) {
v:= http.Header{
"Canonical-Header": []string{"hello_world"},
}
b.ReportAllocs()
b.ResetTimer()
fori:=0; i<b.N; i++ {
s:=v.Get("Canonical-Header")
ifs!="hello_world" {
b.Fatal()
}
}
}
funcBenchmarkNonCanonical(b*testing.B) {
v:= http.Header{
"Canonical-Header": []string{"hello_world"},
}
b.ReportAllocs()
b.ResetTimer()
fori:=0; i<b.N; i++ {
s:=v.Get("CANONICAL-HEADER")
ifs!="hello_world" {
b.Fatal()
}
}
}
goos: darwin
goarch: arm64
pkg: github.com/lasiar/canonicalheader
cpu: Apple M1 Pro
BenchmarkNonCanonical
BenchmarkNonCanonical-8 1407914 848.2 ns/op 16 B/op 1 allocs/op
BenchmarkCanonical
BenchmarkCanonical-8 11176232 107.7 ns/op 0 B/op 0 allocs/op
PASS

@gmlewisgmlewis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @alexandear !
LGTM.
Merging.

@codecov

codecovBot commented Dec 16, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.21%. Comparing base (2b8c7fa) to head (900c040).
Report is 199 commits behind head on master.

Additional details and impacted files
@@ Coverage Diff @@## master #3389 +/- ##
==========================================
- Coverage 97.72% 92.21% -5.51% 
==========================================
Files 153 173 +20 Lines 13390 14770 +1380 ==========================================
+ Hits 13085 13620 +535 - Misses 215 1060 +845 
Partials 90 90 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@gmlewis
gmlewis merged commit 7beb0aa into google:masterDec 16, 2024
jlaportebot added a commit to jlaportebot/go-github that referenced this pull request Jun 28, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@alexandear@gmlewis