From be80aa55ec120b3b6645b3efb77316704d7ad948 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Tue, 15 Mar 2022 13:07:44 +0100 Subject: [PATCH] Removed outdated handling of length parameter to If-Modified-Since header. The length parameter is not described in RFC-7232 and it's against HTTP/1.0 and HTTP/1.1 specifications. It was an old and unofficial extension set by some ancient versions of IE. --- django/views/static.py | 16 +++------------- docs/releases/4.1.txt | 3 +++ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/django/views/static.py b/django/views/static.py index 3d4075be2b..f75b86f970 100644 --- a/django/views/static.py +++ b/django/views/static.py @@ -4,7 +4,6 @@ during development, and SHOULD NOT be used in a production setting. """ import mimetypes import posixpath -import re from pathlib import Path from django.http import FileResponse, Http404, HttpResponse, HttpResponseNotModified @@ -42,7 +41,7 @@ def serve(request, path, document_root=None, show_indexes=False): # Respect the If-Modified-Since header. statobj = fullpath.stat() if not was_modified_since( - request.META.get("HTTP_IF_MODIFIED_SINCE"), statobj.st_mtime, statobj.st_size + request.META.get("HTTP_IF_MODIFIED_SINCE"), statobj.st_mtime ): return HttpResponseNotModified() content_type, encoding = mimetypes.guess_type(str(fullpath)) @@ -111,7 +110,7 @@ def directory_index(path, fullpath): return HttpResponse(t.render(c)) -def was_modified_since(header=None, mtime=0, size=0): +def was_modified_since(header=None, mtime=0): """ Was something modified since the user last downloaded it? @@ -121,20 +120,11 @@ def was_modified_since(header=None, mtime=0, size=0): mtime This is the modification time of the item we're talking about. - - size - This is the size of the item we're talking about. """ try: if header is None: raise ValueError - matches = re.match(r"^([^;]+)(; length=([0-9]+))?$", header, re.IGNORECASE) - if matches is None: - raise ValueError - header_mtime = parse_http_date(matches[1]) - header_len = matches[3] - if header_len and int(header_len) != size: - raise ValueError + header_mtime = parse_http_date(header) if int(mtime) > header_mtime: raise ValueError except (ValueError, OverflowError): diff --git a/docs/releases/4.1.txt b/docs/releases/4.1.txt index 499a67dbd4..a61d5e8e11 100644 --- a/docs/releases/4.1.txt +++ b/docs/releases/4.1.txt @@ -430,6 +430,9 @@ Miscellaneous * The ``exc_info`` argument of the undocumented ``django.utils.log.log_response()`` function is replaced by ``exception``. +* The ``size`` argument of the undocumented + ``django.views.static.was_modified_since()`` function is removed. + .. _deprecated-features-4.1: Features deprecated in 4.1