Skip to content

Commit

Permalink
404 when asking for subpaths
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-goodisman committed Apr 26, 2024
1 parent 00c3a9c commit f75513b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/denylist/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package denylist
import (
"encoding/json"
"net/http"
"strings"
"sync"

"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -66,6 +67,10 @@ func listDenylistKeys(response http.ResponseWriter, denylist *sync.Map) {
// GET /denylist/...
func getDenylistEntry(response http.ResponseWriter, request *http.Request, denylist *sync.Map) {
id := request.URL.Path
if strings.Contains(id, "/") {
http.Error(response, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return
}
_, exists := denylist.Load(id)
if !exists {
http.Error(response, "denylist entry not found with that id", http.StatusNotFound)
Expand All @@ -84,6 +89,10 @@ func getDenylistEntry(response http.ResponseWriter, request *http.Request, denyl
// PUT /denylist/...
func createDenylistEntry(response http.ResponseWriter, request *http.Request, denylist *sync.Map) {
id := request.URL.Path
if strings.Contains(id, "/") {
http.Error(response, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return
}
_, exists := denylist.Load(id)
if exists {
response.WriteHeader(http.StatusNoContent)
Expand All @@ -100,6 +109,10 @@ func createDenylistEntry(response http.ResponseWriter, request *http.Request, de
// DELETE /denylist/...
func deleteDenylistEntry(response http.ResponseWriter, request *http.Request, denylist *sync.Map) {
id := request.URL.Path
if strings.Contains(id, "/") {
http.Error(response, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return
}
_, exists := denylist.Load(id)
if !exists {
http.Error(response, "denylist entry not found with that id", http.StatusNotFound)
Expand Down

0 comments on commit f75513b

Please sign in to comment.