Skip to content

Commit

Permalink
ref: Remove ChunkedMiddleware (#20043)
Browse files Browse the repository at this point in the history
In #20024 we have verified that this middleware is unused with the introduction of Relay.
  • Loading branch information
untitaker committed Jul 27, 2020
1 parent e2e141c commit 4ca2cee
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 66 deletions.
1 change: 0 additions & 1 deletion src/sentry/conf/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ def env(key, default="", type=None):
# response modifying middleware reset the Content-Length header.
# This is because CommonMiddleware Sets the Content-Length header for non-streaming responses.
MIDDLEWARE_CLASSES = (
"sentry.middleware.proxy.ChunkedMiddleware",
"sentry.middleware.proxy.DecompressBodyMiddleware",
"sentry.middleware.security.SecurityHeadersMiddleware",
"sentry.middleware.maintenance.ServicesUnavailableMiddleware",
Expand Down
65 changes: 0 additions & 65 deletions src/sentry/middleware/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,13 @@
import logging
import zlib

try:
import uwsgi

has_uwsgi = True
except ImportError:
has_uwsgi = False

from django.conf import settings
from django.core.exceptions import MiddlewareNotUsed

from sentry.utils import metrics

logger = logging.getLogger(__name__)
Z_CHUNK = 1024 * 8


if has_uwsgi:

class UWsgiChunkedInput(io.RawIOBase):
def __init__(self):
self._internal_buffer = b""

def readable(self):
return True

def readinto(self, buf):
if not self._internal_buffer:
self._internal_buffer = uwsgi.chunked_read()

n = min(len(buf), len(self._internal_buffer))
if n > 0:
buf[:n] = self._internal_buffer[:n]
self._internal_buffer = self._internal_buffer[n:]

return n


class ZDecoder(io.RawIOBase):
"""
Base class for HTTP content decoders based on zlib
Expand Down Expand Up @@ -137,41 +107,6 @@ def process_request(self, request):
request.META["REMOTE_ADDR"] = real_ip


class ChunkedMiddleware(object):
def __init__(self):
if not has_uwsgi:
raise MiddlewareNotUsed

def process_request(self, request):
# If we are dealing with chunked data and we have uwsgi we assume
# that we can read to the end of the input stream so we can bypass
# the default limited stream. We set the content length reasonably
# high so that the reads generally succeed. This is ugly but with
# Django 1.6 it seems to be the best we can easily do.
if "HTTP_TRANSFER_ENCODING" not in request.META:
return

if request.META["HTTP_TRANSFER_ENCODING"].lower() == "chunked":
request._stream = io.BufferedReader(UWsgiChunkedInput())
request.META["CONTENT_LENGTH"] = "4294967295" # 0xffffffff

def process_response(self, request, response):
self._process_response_impl(request, response)
return response

def _process_response_impl(self, request, response):
if "HTTP_TRANSFER_ENCODING" not in request.META:
return

if request.META["HTTP_TRANSFER_ENCODING"].lower() == "chunked":
view = getattr(request, "_view_path", None) or "null"

metrics.incr(
"middleware.proxy.chunked_upload.done",
tags={"method": request.method, "view": view},
)


class DecompressBodyMiddleware(object):
def process_request(self, request):
decode = False
Expand Down

0 comments on commit 4ca2cee

Please sign in to comment.