1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

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.
This commit is contained in:
Mariusz Felisiak 2022-03-15 13:07:44 +01:00 committed by GitHub
parent a88fab1bca
commit be80aa55ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 13 deletions

View File

@ -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):

View File

@ -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