cgilsxml.py: désactiver le cache par défaut
This commit is contained in:
parent
881b3b441f
commit
6c73940ffb
|
@ -173,6 +173,11 @@ def select_file(files, name):
|
|||
if matches: return matches[0]
|
||||
else: return None
|
||||
|
||||
def cgi_nocache():
|
||||
print "Cache-Control: private, no-cache, no-store, must-revalidate, max-age=0"
|
||||
print "Pragma: no-cache"
|
||||
print "Expires: Thu, 01 Jan 1970 00:00:00 GMT"
|
||||
|
||||
def print_files(files, fgroups=None, select_group=None, script_name=None, query_string=None, xslt=None):
|
||||
xresult = ET.Element("result")
|
||||
xenv = ET.SubElement(xresult, "env")
|
||||
|
@ -228,6 +233,8 @@ def run_cgilsxml():
|
|||
+ u"\n Il est possible de spécifier plusieurs champs pour le tri en les séparant par des virgules.")
|
||||
OP.add_option('--cgi', dest='cgi_mode', action='store_true',
|
||||
help=u"Activer le mode CGI. Ce mode est automatiquement activé si la variable d'environnement REQUEST_METHOD existe.")
|
||||
OP.add_option('--cgi-allow-cache', dest='cgi_allow_cache', action='store_true',
|
||||
help=u"En mode CGI, ne pas rajouter les en-tête désactivant la mise en cache du résultat.")
|
||||
OP.add_option('-P', '--cgi-path-info', dest='path_info',
|
||||
help=u"Spécifier un chemin d'un fichier à télécharger. En mode CGI, cette valeur est prise dans la variable d'environnement PATH_INFO")
|
||||
OP.add_option('-Q', '--cgi-query-string', dest='query_string',
|
||||
|
@ -252,6 +259,7 @@ def run_cgilsxml():
|
|||
sortby = o.sortby
|
||||
|
||||
environ = os.environ
|
||||
cgi_cache = o.cgi_allow_cache and True or False
|
||||
cgi_mode = o.cgi_mode
|
||||
if cgi_mode is None:
|
||||
cgi_mode = 'REQUEST_METHOD' in environ
|
||||
|
@ -303,11 +311,13 @@ def run_cgilsxml():
|
|||
file = select_file(files, cgi_path_info)
|
||||
if file is None:
|
||||
if cgi_mode:
|
||||
if not cgi_cache: cgi_nocache()
|
||||
print "Content-Type: text/plain; charset=UTF-8"
|
||||
print
|
||||
print "Impossible de trouver le fichier %s" % cgi_path_info
|
||||
else:
|
||||
if cgi_mode:
|
||||
if not cgi_cache: cgi_nocache()
|
||||
dlname = file.dlname or file.name
|
||||
ctype = file.has_key('type') and file.type or None
|
||||
if ctype is None: ctype, encoding = mimetypes.guess_type(dlname, False)
|
||||
|
@ -321,6 +331,7 @@ def run_cgilsxml():
|
|||
sys.exit()
|
||||
|
||||
if cgi_mode:
|
||||
if not cgi_cache: cgi_nocache()
|
||||
print "Content-Type: text/xml; charset=UTF-8"
|
||||
print
|
||||
print_files(files, fgroups, cgi_select_group, cgi_script_name, cgi_query_string, cgi_xslt)
|
||||
|
|
Loading…
Reference in New Issue