Skip to content

Commit

Permalink
Set no-cache flag when serving a file
Browse files Browse the repository at this point in the history
Previously, a file served through FileServerMiddleware could be re-used by
a client browser without asking the server whether there's a new
version of the file. Now the client is told to always ask whether the file
was changed instead of just using the cached file.

This is necessary, e.g. if the contest admins make changes to a task
statement during the contest, so contestants won't still get served the
previous version they've already downloaded because the browser assumes
it's a persistent file.
  • Loading branch information
magula authored and andreyv committed Feb 7, 2021
1 parent a2c3544 commit 7f77a52
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions cms/server/file_middleware.py
Expand Up @@ -2,6 +2,7 @@

# Contest Management System - http://cms-dev.github.io/
# Copyright © 2018 Luca Wehrstedt <luca.wehrstedt@gmail.com>
# Copyright © 2021 Manuel Gundlach <manuel.gundlach@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
Expand All @@ -23,9 +24,6 @@
from cms.db.filecacher import FileCacher, TombstoneError


SECONDS_IN_A_YEAR = 365 * 24 * 60 * 60


class FileServerMiddleware:
"""Intercept requests wanting to serve files and serve those files.
Expand Down Expand Up @@ -105,7 +103,7 @@ def wsgi_app(self, environ, start_response):
response.headers.add(
"Content-Disposition", "attachment", filename=filename)
response.set_etag(digest)
response.cache_control.max_age = SECONDS_IN_A_YEAR
response.cache_control.no_cache = True
response.cache_control.private = True
response.response = \
wrap_file(environ, fobj, buffer_size=FileCacher.CHUNK_SIZE)
Expand Down

0 comments on commit 7f77a52

Please sign in to comment.