Skip to content

Commit 9ddf2fa

Browse files
Thomas StrombergThomas Stromberg
authored andcommitted
more tests, more caching
1 parent ba9ac84 commit 9ddf2fa

File tree

8 files changed

+1244
-205
lines changed

8 files changed

+1244
-205
lines changed

cmd/server/main.go

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ var (
4646
leEmail = flag.String("le-email", "", "Contact email for Let's Encrypt notifications")
4747
maxConnsPerIP = flag.Int("max-conns-per-ip", 10, "Maximum WebSocket connections per IP")
4848
maxConnsTotal = flag.Int("max-conns-total", 1000, "Maximum total WebSocket connections")
49-
rateLimit = flag.Int("rate-limit", 100, "Maximum requests per minute per IP")
5049
allowedEvents = flag.String("allowed-events", func() string {
5150
if value := os.Getenv("ALLOWED_WEBHOOK_EVENTS"); value != "" {
5251
return value
@@ -92,8 +91,7 @@ func main() {
9291
hub := srv.NewHub()
9392
go hub.Run(ctx)
9493

95-
// Create security components
96-
rateLimiter := security.NewRateLimiter(*rateLimit)
94+
// Create connection limiter for WebSocket connections
9795
connLimiter := security.NewConnectionLimiter(*maxConnsPerIP, *maxConnsTotal)
9896

9997
mux := http.NewServeMux()
@@ -133,16 +131,6 @@ func main() {
133131
return
134132
}
135133

136-
// Rate limiting
137-
if !rateLimiter.Allow(ip) {
138-
log.Printf("Webhook 429: rate limit exceeded ip=%s", ip)
139-
w.WriteHeader(http.StatusTooManyRequests)
140-
if _, err := w.Write([]byte("429 Too Many Requests: Rate limit exceeded\n")); err != nil {
141-
log.Printf("failed to write 429 response: %v", err)
142-
}
143-
return
144-
}
145-
146134
webhookHandler.ServeHTTP(w, r)
147135
log.Printf("Webhook complete: ip=%s duration=%v", ip, time.Since(startTime))
148136
})
@@ -185,16 +173,6 @@ func main() {
185173
return
186174
}
187175

188-
// Rate limiting check
189-
if !rateLimiter.Allow(ip) {
190-
log.Printf("WebSocket 429: rate limit exceeded ip=%s", ip)
191-
w.WriteHeader(http.StatusTooManyRequests)
192-
if _, err := w.Write([]byte("429 Too Many Requests: Rate limit exceeded\n")); err != nil {
193-
log.Printf("failed to write 429 response: %v", err)
194-
}
195-
return
196-
}
197-
198176
// Pre-validate authentication before WebSocket upgrade
199177
authHeader := r.Header.Get("Authorization")
200178
if !wsHandler.PreValidateAuth(r) {
@@ -287,9 +265,6 @@ func main() {
287265
// Stop accepting new connections
288266
hub.Stop()
289267

290-
// Stop the rate limiter cleanup routine
291-
rateLimiter.Stop()
292-
293268
// Stop the connection limiter cleanup routine
294269
connLimiter.Stop()
295270

0 commit comments

Comments
 (0)