Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
7bf7eab6
Commit
7bf7eab6
authored
Sep 26, 2012
by
Chris Dodge
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support client-side caching through 'Last-Modified' response headers
parent
7512b78e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
6 deletions
+22
-6
common/djangoapps/contentserver/middleware.py
+19
-3
common/lib/xmodule/xmodule/contentstore/__init__.py
+2
-1
common/lib/xmodule/xmodule/contentstore/mongo.py
+1
-2
No files found.
common/djangoapps/contentserver/middleware.py
View file @
7bf7eab6
import
logging
import
time
from
django.http
import
HttpResponse
,
Http404
from
django.http
import
HttpResponse
,
Http404
,
HttpResponseNotModified
from
xmodule.contentstore.django
import
contentstore
from
xmodule.contentstore
import
StaticContent
...
...
@@ -30,7 +31,22 @@ class StaticContentServer(object):
else
:
logging
.
debug
(
'cache hit on {0}'
.
format
(
content
.
filename
))
# see if the last-modified at hasn't changed, if not return a 302 (Not Modified)
logging
.
debug
(
request
.
META
)
# convert over the DB persistent last modified timestamp to a HTTP compatible
# timestamp
last_modified_at_str
=
content
.
last_modified_at
.
strftime
(
"
%
a,
%
d-
%
b-
%
Y
%
H:
%
M:
%
S GMT"
)
# see if the client has cached this content, if so then compare the
# timestamps, if they are the same then just return a 304 (Not Modified)
if
'HTTP_IF_MODIFIED_SINCE'
in
request
.
META
:
if_modified_since
=
request
.
META
[
'HTTP_IF_MODIFIED_SINCE'
]
if
if_modified_since
==
last_modified_at_str
:
return
HttpResponseNotModified
()
response
=
HttpResponse
(
content
.
data
,
content_type
=
content
.
content_type
)
response
[
'
Content-Disposition'
]
=
'attachment; filename={0}'
.
format
(
content
.
name
)
response
[
'
Last-Modified'
]
=
last_modified_at_str
return
response
common/lib/xmodule/xmodule/contentstore/__init__.py
View file @
7bf7eab6
class
StaticContent
(
object
):
def
__init__
(
self
,
filename
,
name
,
content_type
,
data
):
def
__init__
(
self
,
filename
,
name
,
content_type
,
data
,
last_modified_at
=
None
):
self
.
filename
=
filename
self
.
name
=
name
self
.
content_type
=
content_type
self
.
data
=
data
self
.
last_modified_at
=
last_modified_at
@staticmethod
def
get_location_tag
():
...
...
common/lib/xmodule/xmodule/contentstore/mongo.py
View file @
7bf7eab6
...
...
@@ -23,8 +23,7 @@ class MongoContentStore(object):
def
find
(
self
,
filename
):
try
:
with
self
.
fs
.
get_last_version
(
filename
)
as
fp
:
logging
.
debug
(
'fetched {0}'
.
format
(
fp
.
name
))
return
StaticContent
(
fp
.
filename
,
fp
.
displayname
,
fp
.
content_type
,
fp
.
read
())
return
StaticContent
(
fp
.
filename
,
fp
.
displayname
,
fp
.
content_type
,
fp
.
read
(),
fp
.
uploadDate
)
except
NoFile
:
raise
NotFoundError
()
...
...
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