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:
parent
a90c96dab3
commit
127038917b
@ -11,7 +11,9 @@ def app(root=None,
|
|||||||
log_req_frmt="%(bottle.request)s",
|
log_req_frmt="%(bottle.request)s",
|
||||||
log_res_frmt="%(status)s",
|
log_res_frmt="%(status)s",
|
||||||
log_err_frmt="%(body)s: %(exception)s \n%(traceback)s",
|
log_err_frmt="%(body)s: %(exception)s \n%(traceback)s",
|
||||||
welcome_file=None):
|
welcome_file=None,
|
||||||
|
cache_control=None,
|
||||||
|
):
|
||||||
import sys, os
|
import sys, os
|
||||||
from pypiserver import core
|
from pypiserver import core
|
||||||
sys.modules.pop("pypiserver._app", None)
|
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,
|
_app.configure(root=root, redirect_to_fallback=redirect_to_fallback, fallback_url=fallback_url,
|
||||||
authenticated=authenticated, password_file=password_file, overwrite=overwrite,
|
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,
|
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
|
_app.app.module = _app
|
||||||
|
|
||||||
bottle.debug(True)
|
bottle.debug(True)
|
||||||
|
@ -63,7 +63,9 @@ def configure(root=None,
|
|||||||
log_req_frmt=None,
|
log_req_frmt=None,
|
||||||
log_res_frmt=None,
|
log_res_frmt=None,
|
||||||
log_err_frmt=None,
|
log_err_frmt=None,
|
||||||
welcome_file=None):
|
welcome_file=None,
|
||||||
|
cache_control=None,
|
||||||
|
):
|
||||||
global packages
|
global packages
|
||||||
|
|
||||||
log.info("Starting(%s)", dict(root=root,
|
log.info("Starting(%s)", dict(root=root,
|
||||||
@ -75,7 +77,8 @@ def configure(root=None,
|
|||||||
welcome_file=welcome_file,
|
welcome_file=welcome_file,
|
||||||
log_req_frmt=log_req_frmt,
|
log_req_frmt=log_req_frmt,
|
||||||
log_res_frmt=log_res_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
|
config.authenticated = authenticated
|
||||||
|
|
||||||
@ -103,6 +106,7 @@ def configure(root=None,
|
|||||||
|
|
||||||
config.redirect_to_fallback = redirect_to_fallback
|
config.redirect_to_fallback = redirect_to_fallback
|
||||||
config.fallback_url = fallback_url
|
config.fallback_url = fallback_url
|
||||||
|
config.cache_control = cache_control
|
||||||
if password_file:
|
if password_file:
|
||||||
from passlib.apache import HtpasswdFile
|
from passlib.apache import HtpasswdFile
|
||||||
config.htpasswdfile = HtpasswdFile(password_file)
|
config.htpasswdfile = HtpasswdFile(password_file)
|
||||||
@ -314,7 +318,10 @@ def server_static(filename):
|
|||||||
for x in entries:
|
for x in entries:
|
||||||
f = x.relfn.replace("\\", "/")
|
f = x.relfn.replace("\\", "/")
|
||||||
if f == filename:
|
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)
|
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.
|
a format-string selecting Http-Error properties to log; set to '%s' to see them all.
|
||||||
[Default: %(body)s: %(exception)s \n%(traceback)s]
|
[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 -h
|
||||||
pypi-server --help
|
pypi-server --help
|
||||||
show this help message
|
show this help message
|
||||||
@ -300,6 +305,7 @@ def main(argv=None):
|
|||||||
log_res_frmt = None
|
log_res_frmt = None
|
||||||
log_err_frmt = None
|
log_err_frmt = None
|
||||||
welcome_file = None
|
welcome_file = None
|
||||||
|
cache_control = None
|
||||||
|
|
||||||
update_dry_run = True
|
update_dry_run = True
|
||||||
update_directory = None
|
update_directory = None
|
||||||
@ -322,6 +328,7 @@ def main(argv=None):
|
|||||||
"log-res-frmt=",
|
"log-res-frmt=",
|
||||||
"log-err-frmt=",
|
"log-err-frmt=",
|
||||||
"welcome=",
|
"welcome=",
|
||||||
|
"cache-control=",
|
||||||
"version",
|
"version",
|
||||||
"help"
|
"help"
|
||||||
])
|
])
|
||||||
@ -379,6 +386,8 @@ def main(argv=None):
|
|||||||
log_res_frmt = v
|
log_res_frmt = v
|
||||||
elif k == "--log-err-frmt":
|
elif k == "--log-err-frmt":
|
||||||
log_err_frmt = v
|
log_err_frmt = v
|
||||||
|
elif k == "--cache-control":
|
||||||
|
cache_control = v
|
||||||
elif k == "-v":
|
elif k == "-v":
|
||||||
verbosity += 1
|
verbosity += 1
|
||||||
elif k in ("-h", "--help"):
|
elif k in ("-h", "--help"):
|
||||||
@ -412,6 +421,7 @@ def main(argv=None):
|
|||||||
overwrite=overwrite,
|
overwrite=overwrite,
|
||||||
log_req_frmt=log_req_frmt, log_res_frmt=log_res_frmt, log_err_frmt=log_err_frmt,
|
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,
|
||||||
)
|
)
|
||||||
server = server or "auto"
|
server = server or "auto"
|
||||||
sys.stdout.write("This is pypiserver %s serving %r on http://%s:%s\n\n" % (__version__, ", ".join(roots), host, port))
|
sys.stdout.write("This is pypiserver %s serving %r on http://%s:%s\n\n" % (__version__, ", ".join(roots), host, port))
|
||||||
|
Loading…
Reference in New Issue
Block a user