fix: [UI caching] fix: #373 avoid screenshot caching

This commit is contained in:
Terrtia 2019-09-03 11:58:34 +02:00
parent dfd1128daa
commit 6dcecd6ba6
No known key found for this signature in database
GPG key ID: 1E1B1F50D84613D0
3 changed files with 20 additions and 3 deletions

View file

@ -178,7 +178,8 @@ def add_header(response):
and also to cache the rendered page for 10 minutes.
"""
response.headers['X-UA-Compatible'] = 'IE=Edge,chrome=1'
response.headers['Cache-Control'] = 'public, max-age=0'
if 'Cache-Control' not in response.headers:
response.headers['Cache-Control'] = 'private, max-age=0'
return response
# @app.route('/test', methods=['GET'])

View file

@ -10,7 +10,7 @@ import configparser
from functools import wraps
from flask_login import LoginManager, current_user, login_user, logout_user, login_required
from flask import request, current_app
from flask import request, make_response, current_app
login_manager = LoginManager()
login_manager.login_view = 'role'
@ -36,6 +36,21 @@ default_passwd_file = os.path.join(os.environ['AIL_HOME'], 'DEFAULT_PASSWORD')
regex_password = r'^(?=(.*\d){2})(?=.*[a-z])(?=.*[A-Z]).{10,100}$'
regex_password = re.compile(regex_password)
###############################################################
############### CHECK ROLE ACCESS ##################
###############################################################
def no_cache(func):
@wraps(func)
def decorated_view(*args, **kwargs):
resp = make_response(func(*args, **kwargs))
resp.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
resp.headers['Pragma'] = 'no-cache'
return resp
return decorated_view
###############################################################
###############################################################
###############################################################
###############################################################
############### CHECK ROLE ACCESS ##################
###############################################################

View file

@ -10,7 +10,7 @@ import os
import flask
from flask import Flask, render_template, jsonify, request, Blueprint, make_response, Response, send_from_directory, redirect, url_for
from Role_Manager import login_admin, login_analyst
from Role_Manager import login_admin, login_analyst, no_cache
from flask_login import login_required
import difflib
@ -446,6 +446,7 @@ def showDiff():
@showsavedpastes.route('/screenshot/<path:filename>')
@login_required
@login_analyst
@no_cache
def screenshot(filename):
return send_from_directory(SCREENSHOT_FOLDER, filename+'.png', as_attachment=True)