1
0
mirror of https://github.com/pypiserver/pypiserver synced 2024-11-09 16:45:51 +01:00

Add cache control header option.

This commit is contained in:
Bartek Rychlicki 2015-01-10 17:43:38 +01:00 committed by Kostis Anagnostopoulos, Yoga-2
parent a90c96dab3
commit 127038917b
3 changed files with 26 additions and 5 deletions

@ -11,7 +11,9 @@ def app(root=None,
log_req_frmt="%(bottle.request)s",
log_res_frmt="%(status)s",
log_err_frmt="%(body)s: %(exception)s \n%(traceback)s",
welcome_file=None):
welcome_file=None,
cache_control=None,
):
import sys, os
from pypiserver import core
sys.modules.pop("pypiserver._app", None)
@ -29,7 +31,9 @@ def app(root=None,
_app.configure(root=root, redirect_to_fallback=redirect_to_fallback, fallback_url=fallback_url,
authenticated=authenticated, password_file=password_file, overwrite=overwrite,
log_req_frmt=log_req_frmt, log_res_frmt=log_res_frmt, log_err_frmt=log_err_frmt,
welcome_file=welcome_file)
welcome_file=welcome_file,
cache_control=cache_control,
)
_app.app.module = _app
bottle.debug(True)

@ -63,7 +63,9 @@ def configure(root=None,
log_req_frmt=None,
log_res_frmt=None,
log_err_frmt=None,
welcome_file=None):
welcome_file=None,
cache_control=None,
):
global packages
log.info("Starting(%s)", dict(root=root,
@ -75,7 +77,8 @@ def configure(root=None,
welcome_file=welcome_file,
log_req_frmt=log_req_frmt,
log_res_frmt=log_res_frmt,
log_err_frmt=log_err_frmt))
log_err_frmt=log_err_frmt,
cache_control=cache_control))
config.authenticated = authenticated
@ -103,6 +106,7 @@ def configure(root=None,
config.redirect_to_fallback = redirect_to_fallback
config.fallback_url = fallback_url
config.cache_control = cache_control
if password_file:
from passlib.apache import HtpasswdFile
config.htpasswdfile = HtpasswdFile(password_file)
@ -314,7 +318,10 @@ def server_static(filename):
for x in entries:
f = x.relfn.replace("\\", "/")
if f == filename:
return static_file(filename, root=x.root, mimetype=mimetypes.guess_type(filename)[0])
response = static_file(filename, root=x.root, mimetype=mimetypes.guess_type(filename)[0])
if config.cache_control:
response.set_header("Cache-Control", "public, max-age=%s" % config.cache_control)
return response
return HTTPError(404)

@ -250,6 +250,11 @@ pypi-server understands the following options:
a format-string selecting Http-Error properties to log; set to '%s' to see them all.
[Default: %(body)s: %(exception)s \n%(traceback)s]
--cache-control AGE
Add "Cache-Control: max-age=AGE, public" header to package downloads.
Pip 6+ needs this for caching.
pypi-server -h
pypi-server --help
show this help message
@ -300,6 +305,7 @@ def main(argv=None):
log_res_frmt = None
log_err_frmt = None
welcome_file = None
cache_control = None
update_dry_run = True
update_directory = None
@ -322,6 +328,7 @@ def main(argv=None):
"log-res-frmt=",
"log-err-frmt=",
"welcome=",
"cache-control=",
"version",
"help"
])
@ -379,6 +386,8 @@ def main(argv=None):
log_res_frmt = v
elif k == "--log-err-frmt":
log_err_frmt = v
elif k == "--cache-control":
cache_control = v
elif k == "-v":
verbosity += 1
elif k in ("-h", "--help"):
@ -412,6 +421,7 @@ def main(argv=None):
overwrite=overwrite,
log_req_frmt=log_req_frmt, log_res_frmt=log_res_frmt, log_err_frmt=log_err_frmt,
welcome_file=welcome_file,
cache_control=cache_control,
)
server = server or "auto"
sys.stdout.write("This is pypiserver %s serving %r on http://%s:%s\n\n" % (__version__, ", ".join(roots), host, port))