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.
- See https://httpwg.org/specs/rfc7232.html#header.if-modified-since
- https://github.com/django/django/pull/15500
pull/8118/head
Mariusz Felisiak 2022-03-15 09:58:31 +01:00 zatwierdzone przez LB (Ben Johnston)
rodzic a412dcc8d5
commit 7b4cf43e2e
4 zmienionych plików z 11 dodań i 12 usunięć

Wyświetl plik

@ -26,6 +26,7 @@ Changelog
* Add documentation for defining custom form validation on models used in Wagtail's `modelAdmin` (Serafeim Papastefanos)
* Update `README.md` logo to work for GitHub dark mode (Paarth Agarwal)
* Avoid an unnecessary page reload when pressing enter within the header search bar (Images, Pages, Documents) (Riley de Mestre)
* Removed unofficial length parameter on `If-Modified-Since` header in `sendfile_streaming_backend` which was only used by IE (Mariusz Felisiak)
* Fix: When using `simple_translations` ensure that the user is redirected to the page edit view when submitting for a single locale (Mitchel Cabuloy)
* Fix: When previewing unsaved changes to `Form` pages, ensure that all added fields are correctly shown in the preview (Joshua Munn)
* Fix: When Documents (e.g. PDFs) have been configured to be served inline via `WAGTAILDOCS_CONTENT_TYPES` & `WAGTAILDOCS_INLINE_CONTENT_TYPES` ensure that the filename is correctly set in the `Content-Disposition` header so that saving the files will use the correct filename (John-Scott Atlakson)

Wyświetl plik

@ -571,6 +571,7 @@ Contributors
* Nicolas Ferrari
* Vibhakar Solanki
* Riley de Mestre
* Mariusz Felisiak
Translators
===========

Wyświetl plik

@ -51,6 +51,7 @@ The panel types `StreamFieldPanel`, `RichTextFieldPanel`, `ImageChooserPanel`, `
* Add documentation for defining [custom form validation](modeladmin_custom_clean) on models used in Wagtail's `modelAdmin` (Serafeim Papastefanos)
* Update `README.md` logo to work for GitHub dark mode (Paarth Agarwal)
* Avoid an unnecessary page reload when pressing enter within the header search bar (Images, Pages, Documents) (Riley de Mestre)
* Removed unofficial length parameter on `If-Modified-Since` header in `sendfile_streaming_backend` which was only used by IE (Mariusz Felisiak)
### Bug fixes
@ -108,3 +109,8 @@ If you do continue to use a custom panel class, note that the template context f
### ModelAdmin forms must subclass `WagtailAdminModelForm`
When overriding the `get_form_class` method of a ModelAdmin `CreateView` or `EditView` to pass a custom form class, that form class must now inherit from `wagtail.admin.forms.models.WagtailAdminModelForm`. Passing a plain Django ModelForm subclass is no longer valid.
### Removed the `size` argument of the undocumented `wagtail.utils.sendfile_streaming_backend.was_modified_since` function
- The `size` argument was used to add a `length` parameter to the HTTP header.
- This was never part of the HTTP/1.0 and HTTP/1.1 specifications see [RFC7232](https://httpwg.org/specs/rfc7232.html#header.if-modified-since) and existed only as a an unofficial implementation in IE browsers.

Wyświetl plik

@ -2,7 +2,6 @@
# This is based on sendfiles builtin "simple" backend but uses a StreamingHttpResponse
import os
import re
import stat
from email.utils import mktime_tz, parsedate_tz
from wsgiref.util import FileWrapper
@ -18,7 +17,6 @@ def sendfile(request, filename, **kwargs):
if not was_modified_since(
request.META.get("HTTP_IF_MODIFIED_SINCE"),
statobj[stat.ST_MTIME],
statobj[stat.ST_SIZE],
):
return HttpResponseNotModified()
@ -28,7 +26,7 @@ def sendfile(request, filename, **kwargs):
return response
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?
@ -38,23 +36,16 @@ 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)
header_date = parsedate_tz(matches.group(1))
header_date = parsedate_tz(header)
if header_date is None:
raise ValueError
header_mtime = mktime_tz(header_date)
header_len = matches.group(3)
if header_len and int(header_len) != size:
raise ValueError
if mtime > header_mtime:
raise ValueError
except (AttributeError, ValueError, OverflowError):
except (ValueError, OverflowError):
return True
return False