mirror of
https://github.com/NotAShelf/watchdog.git
synced 2026-04-15 06:44:20 +00:00
api/handler: O(n) linear scan -> O(1) map lookup
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ic2080f59be1eea905e8ca95e90e34d4d6a6a6964
This commit is contained in:
parent
d2f28ded61
commit
02c4f11619
1 changed files with 3 additions and 8 deletions
|
|
@ -24,7 +24,7 @@ type IngestionHandler struct {
|
|||
metricsAgg *aggregate.MetricsAggregator
|
||||
rateLimiter *ratelimit.TokenBucket
|
||||
rng *rand.Rand
|
||||
trustedNetworks []*net.IPNet // Pre-parsed CIDR networks
|
||||
trustedNetworks []*net.IPNet // pre-parsed CIDR networks
|
||||
}
|
||||
|
||||
// Creates a new ingestion handler
|
||||
|
|
@ -209,13 +209,8 @@ func (h *IngestionHandler) handleCORS(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
// Check if origin is allowed
|
||||
allowed := false
|
||||
for _, allowedOrigin := range h.cfg.Security.CORS.AllowedOrigins {
|
||||
if allowedOrigin == "*" || allowedOrigin == origin {
|
||||
allowed = true
|
||||
break
|
||||
}
|
||||
}
|
||||
// This uses map so that it's O(1)
|
||||
allowed := h.corsOriginMap["*"] || h.corsOriginMap[origin]
|
||||
|
||||
if allowed {
|
||||
if origin == "*" {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue