mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-13 02:18:04 -04:00
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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user