Remove request reading middleware as we use post-buffering (#2094)

# What this PR does

RequestBodyReadingMiddleware is excess as [post-buffering is
enabled](https://github.com/grafana/oncall/blob/dev/engine/uwsgi.ini#L17):

If an HTTP request has a body (like a POST request generated by a form),
you have to read (consume) it in your application. If you do not do
this, the communication socket with your webserver may be clobbered. If
you are lazy you can use the post-buffering option that will
automatically read data for you. For Rack applications this is
automatically enabled.
(https://uwsgi-docs.readthedocs.io/en/latest/ThingsToKnow.html)

## Which issue(s) this PR fixes

## Checklist

- [ ] Unit, integration, and e2e (if applicable) tests updated
- [ ] Documentation added (or `pr:no public docs` PR label added if not
required)
- [ ] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)
This commit is contained in:
Ildar Iskhakov 2023-06-05 11:49:39 +08:00 committed by GitHub
parent 71f9505db8
commit 1bdb54df35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 16 deletions

View file

@ -3,9 +3,8 @@ import logging
from django.apps import apps
from django.conf import settings
from django.core.exceptions import PermissionDenied, RequestDataTooBig
from django.core.exceptions import PermissionDenied
from django.db import OperationalError
from django.http import HttpResponse
from django.utils.deprecation import MiddlewareMixin
logger = logging.getLogger(__name__)
@ -57,19 +56,6 @@ class RequestTimeLoggingMiddleware(MiddlewareMixin):
return response
class RequestBodyReadingMiddleware(MiddlewareMixin):
def process_request(self, request):
# Reading request body, as required by uwsgi
# https://uwsgi-docs.readthedocs.io/en/latest/ThingsToKnow.html
# "If an HTTP request has a body (like a POST request generated by a form),
# you have to read (consume) it in your application.
# If you do not do this, the communication socket with your webserver may be clobbered."
try:
request.body
except RequestDataTooBig:
return HttpResponse(status=400)
class BanAlertConsumptionBasedOnSettingsMiddleware(MiddlewareMixin):
"""
Banning requests for /integrations/v1

View file

@ -245,7 +245,6 @@ MIDDLEWARE = [
"log_request_id.middleware.RequestIDMiddleware",
"engine.middlewares.RequestTimeLoggingMiddleware",
"engine.middlewares.BanAlertConsumptionBasedOnSettingsMiddleware",
"engine.middlewares.RequestBodyReadingMiddleware",
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"debug_toolbar.middleware.DebugToolbarMiddleware",