forked from retoor/devplacepy
fix: add DEVPLACE_DISABLE_RATE_LIMIT env var to bypass middleware in tests
Add a RATE_LIMIT_DISABLED flag read from DEVPLACE_DISABLE_RATE_LIMIT env var that short-circuits the rate_limit_middleware when set, allowing test suites to disable per-IP throttling globally in conftest while individual rate-limit tests re-enable it via monkeypatch.
This commit is contained in:
@@ -88,6 +88,7 @@ _rate_limit_store = defaultdict(list)
|
||||
RATE_LIMIT = int(os.environ.get("DEVPLACE_RATE_LIMIT", "60"))
|
||||
RATE_WINDOW = 60
|
||||
WEB_WORKERS = max(1, int(os.environ.get("DEVPLACE_WEB_WORKERS", "1")))
|
||||
RATE_LIMIT_DISABLED = os.environ.get("DEVPLACE_DISABLE_RATE_LIMIT") == "1"
|
||||
|
||||
|
||||
def _worker_rate_limit(limit: int) -> int:
|
||||
@@ -326,6 +327,8 @@ async def add_security_headers(request: Request, call_next):
|
||||
|
||||
@app.middleware("http")
|
||||
async def rate_limit_middleware(request: Request, call_next):
|
||||
if RATE_LIMIT_DISABLED:
|
||||
return await call_next(request)
|
||||
if request.method in (
|
||||
"POST",
|
||||
"PUT",
|
||||
|
||||
Reference in New Issue
Block a user