Skip to content

Commit 4b6fe57

Browse files
committed
[REFACTOR] Remove custom contains in favor of std lib impl
1 parent 9dd6af1 commit 4b6fe57

File tree

2 files changed

+1
-13
lines changed

2 files changed

+1
-13
lines changed

csrf.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ func (cs *csrf) ServeHTTP(w http.ResponseWriter, r *http.Request) {
254254

255255
// HTTP methods not defined as idempotent ("safe") under RFC7231 require
256256
// inspection.
257-
if !contains(safeMethods, r.Method) {
257+
if !slices.Contains(safeMethods, r.Method) {
258258
var isPlaintext bool
259259
val := r.Context().Value(PlaintextHTTPContextKey)
260260
if val != nil {

helpers.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -189,18 +189,6 @@ func xorToken(a, b []byte) []byte {
189189
return res
190190
}
191191

192-
// contains is a helper function to check if a string exists in a slice - e.g.
193-
// whether a HTTP method exists in a list of safe methods.
194-
func contains(vals []string, s string) bool {
195-
for _, v := range vals {
196-
if v == s {
197-
return true
198-
}
199-
}
200-
201-
return false
202-
}
203-
204192
// envError stores a CSRF error in the request context.
205193
func envError(r *http.Request, err error) *http.Request {
206194
return contextSave(r, errorKey, err)

0 commit comments

Comments
 (0)