Skip to content

Commit

Permalink
Rename Subsumes method to Accepts
Browse files Browse the repository at this point in the history
  • Loading branch information
jub0bs committed Aug 29, 2024
1 parent c5e2bf2 commit 91d8985
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion cors.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ func (c *Cors) handlePreflight(w http.ResponseWriter, r *http.Request) {
// However, some gateways split that header into multiple headers of the same name;
// see https://github.com/rs/cors/issues/184.
reqHeaders, found := r.Header["Access-Control-Request-Headers"]
if found && !c.allowedHeadersAll && !c.allowedHeaders.Subsumes(reqHeaders) {
if found && !c.allowedHeadersAll && !c.allowedHeaders.Accepts(reqHeaders) {
c.logf(" Preflight aborted: headers '%v' not allowed", reqHeaders)
return
}
Expand Down
4 changes: 2 additions & 2 deletions internal/sortedset.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ func (set SortedSet) String() string {
return strings.Join(elems, ",")
}

// Subsumes reports whether values is a sequence of list-based field values
// Accepts reports whether values is a sequence of list-based field values
// whose elements are
// - all members of set,
// - sorted in lexicographical order,
// - unique.
func (set SortedSet) Subsumes(values []string) bool {
func (set SortedSet) Accepts(values []string) bool {
var ( // effectively constant
maxLen = maxOWSBytes + set.maxLen + maxOWSBytes + 1 // +1 for comma
)
Expand Down
42 changes: 21 additions & 21 deletions internal/sortedset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ func TestSortedSet(t *testing.T) {
desc string
elems []string
// expectations
size int
combined string
slice []string
subsets [][]string
notSubsets [][]string
size int
combined string
slice []string
accepted [][]string
rejected [][]string
}{
{
desc: "empty set",
size: 0,
combined: "",
subsets: [][]string{
accepted: [][]string{
// some empty elements, possibly with OWS
{""},
{","},
{"\t, , "},
// multiple field lines, some empty elements
make([]string, maxEmptyElements),
},
notSubsets: [][]string{
rejected: [][]string{
{"x-bar"},
{"x-bar,x-foo"},
// too many empty elements
Expand All @@ -42,7 +42,7 @@ func TestSortedSet(t *testing.T) {
size: 1,
combined: "x-foo",
slice: []string{"X-Foo"},
subsets: [][]string{
accepted: [][]string{
{"x-foo"},
// some empty elements, possibly with OWS
{""},
Expand All @@ -55,7 +55,7 @@ func TestSortedSet(t *testing.T) {
append(make([]string, maxEmptyElements), "x-foo"),
make([]string, maxEmptyElements),
},
notSubsets: [][]string{
rejected: [][]string{
{"x-bar"},
{"x-bar,x-foo"},
// too much OWS
Expand All @@ -77,7 +77,7 @@ func TestSortedSet(t *testing.T) {
size: 3,
combined: "x-bar,x-baz,x-foo",
slice: []string{"X-Bar", "X-Baz", "X-Foo"},
subsets: [][]string{
accepted: [][]string{
{"x-bar"},
{"x-baz"},
{"x-foo"},
Expand All @@ -104,7 +104,7 @@ func TestSortedSet(t *testing.T) {
append(make([]string, maxEmptyElements), "x-bar", "x-foo"),
make([]string, maxEmptyElements),
},
notSubsets: [][]string{
rejected: [][]string{
{"x-qux"},
{"x-bar,x-baz,x-baz"},
{"x-qux,x-baz"},
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestSortedSet(t *testing.T) {
size: 2,
combined: "x-bar,x-foo",
slice: []string{"X-Bar", "X-Foo"},
subsets: [][]string{
accepted: [][]string{
{"x-bar"},
{"x-foo"},
{"x-bar,x-foo"},
Expand All @@ -154,7 +154,7 @@ func TestSortedSet(t *testing.T) {
append(make([]string, maxEmptyElements), "x-bar", "x-foo"),
make([]string, maxEmptyElements),
},
notSubsets: [][]string{
rejected: [][]string{
{"x-qux"},
{"x-qux,x-bar"},
{"x-qux,x-foo"},
Expand Down Expand Up @@ -192,16 +192,16 @@ func TestSortedSet(t *testing.T) {
const tmpl = "NewSortedSet(%#v...).String(): got %q; want %q"
t.Errorf(tmpl, elems, combined, tc.combined)
}
for _, sub := range tc.subsets {
if !set.Subsumes(sub) {
const tmpl = "%q is not a subset of %q, but should be"
t.Errorf(tmpl, set, sub)
for _, a := range tc.accepted {
if !set.Accepts(a) {
const tmpl = "%q rejects %q, but should accept it"
t.Errorf(tmpl, set, a)
}
}
for _, notSub := range tc.notSubsets {
if set.Subsumes(notSub) {
const tmpl = "%q is a subset of %q, but should not be"
t.Errorf(tmpl, set, notSub)
for _, r := range tc.rejected {
if set.Accepts(r) {
const tmpl = "%q accepts %q, but should reject it"
t.Errorf(tmpl, set, r)
}
}
}
Expand Down

0 comments on commit 91d8985

Please sign in to comment.