Add before_request check for request size

The test checks various routes to ensure that request above our
threshold fail before any other processing happens
This commit is contained in:
sakisv
2021-01-28 14:01:10 +02:00
parent d35ab04a4e
commit 238dcae23c
2 changed files with 46 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ from notifications_utils.clients.encryption.encryption_client import Encryption
from notifications_utils import logging, request_helper
from sqlalchemy import event
from werkzeug.exceptions import HTTPException as WerkzeugHTTPException
from werkzeug.exceptions import RequestEntityTooLarge as WerkzeugRequestEntityTooLarge
from werkzeug.local import LocalProxy
from app.celery.celery import NotifyCelery
@@ -281,6 +282,15 @@ def init_app(app):
g.start = monotonic()
g.endpoint = request.endpoint
@app.before_request
def check_content_length():
if (
request.content_length is not None
and current_app.config['MAX_CONTENT_LENGTH'] is not None
and request.content_length > current_app.config['MAX_CONTENT_LENGTH']
):
raise WerkzeugRequestEntityTooLarge()
@app.after_request
def after_request(response):
CONCURRENT_REQUESTS.dec()