Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Websites UFRPE
Django Private Storage
Commits
eb7d8048
Commit
eb7d8048
authored
Feb 07, 2017
by
Diederik van der Boor
Browse files
Add If-Modified-Since support
parent
c7abf477
Changes
1
Hide whitespace changes
Inline
Side-by-side
private_storage/servers.py
View file @
eb7d8048
...
...
@@ -6,10 +6,11 @@ import os
from
django.conf
import
settings
from
django.core.exceptions
import
ImproperlyConfigured
from
django.http
import
FileResponse
,
HttpResponse
from
django.http
import
HttpResponseNotModified
from
django.utils.http
import
http_date
from
django.utils.lru_cache
import
lru_cache
from
django.utils.module_loading
import
import_string
from
django.views.static
import
serve
from
django.views.static
import
serve
,
was_modified_since
@
lru_cache
()
...
...
@@ -37,11 +38,17 @@ class DjangoStreamingServer(object):
@
staticmethod
def
serve
(
private_file
):
# Support If-Last-Modified
mtime
=
private_file
.
modified_time
.
timestamp
()
size
=
private_file
.
size
if
not
was_modified_since
(
private_file
.
request
.
META
.
get
(
'HTTP_IF_MODIFIED_SINCE'
),
mtime
,
size
):
return
HttpResponseNotModified
()
# FileResponse will submit the file in 8KB chunks
response
=
FileResponse
(
private_file
.
open
())
response
[
'Content-Type'
]
=
private_file
.
content_type
response
[
'Content-Length'
]
=
private_file
.
size
response
[
"Last-Modified"
]
=
http_date
(
private_file
.
modified_time
.
timestamp
()
)
response
[
'Content-Length'
]
=
size
response
[
"Last-Modified"
]
=
http_date
(
mtime
)
return
response
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment