mirror of
https://github.com/NotAShelf/watchdog.git
synced 2026-04-17 23:58:19 +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
|
metricsAgg *aggregate.MetricsAggregator
|
||||||
rateLimiter *ratelimit.TokenBucket
|
rateLimiter *ratelimit.TokenBucket
|
||||||
rng *rand.Rand
|
rng *rand.Rand
|
||||||
trustedNetworks []*net.IPNet // Pre-parsed CIDR networks
|
trustedNetworks []*net.IPNet // pre-parsed CIDR networks
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a new ingestion handler
|
// Creates a new ingestion handler
|
||||||
|
|
@ -209,13 +209,8 @@ func (h *IngestionHandler) handleCORS(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if origin is allowed
|
// Check if origin is allowed
|
||||||
allowed := false
|
// This uses map so that it's O(1)
|
||||||
for _, allowedOrigin := range h.cfg.Security.CORS.AllowedOrigins {
|
allowed := h.corsOriginMap["*"] || h.corsOriginMap[origin]
|
||||||
if allowedOrigin == "*" || allowedOrigin == origin {
|
|
||||||
allowed = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if allowed {
|
if allowed {
|
||||||
if origin == "*" {
|
if origin == "*" {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue