Merge pull request #1035 from Salandora/edgeFix

Edge Fix
This commit is contained in:
Gina Häußge 2015-08-28 08:57:38 +02:00
commit 5df088cfee
5 changed files with 29 additions and 4 deletions

View file

@ -19,7 +19,7 @@ import octoprint.server
import octoprint.plugin
from octoprint.server import admin_permission, NO_CONTENT
from octoprint.settings import settings as s, valid_boolean_trues
from octoprint.server.util import apiKeyRequestHandler, corsResponseHandler
from octoprint.server.util import noCachingResponseHandler, apiKeyRequestHandler, corsResponseHandler
from octoprint.server.util.flask import restricted_access, get_json_command_from_request, passive_login
@ -42,6 +42,8 @@ from . import languages as api_languages
VERSION = "0.1"
api.after_request(noCachingResponseHandler)
api.before_request(apiKeyRequestHandler)
api.after_request(corsResponseHandler)

View file

@ -10,10 +10,15 @@ from flask import Blueprint, request, make_response, jsonify
import octoprint.server
import octoprint.plugin
from octoprint.server.util import noCachingResponseHandler, corsResponseHandler
from octoprint.settings import settings as s
apps = Blueprint("apps", __name__)
apps.after_request(noCachingResponseHandler)
apps.after_request(corsResponseHandler)
@apps.route("/auth", methods=["GET"])
def getSessionKey():
unverified_key, valid_until = octoprint.server.appSessionManager.create()

View file

@ -80,6 +80,18 @@ def corsResponseHandler(resp):
return resp
def noCachingResponseHandler(resp):
"""
``after_request`` handler for blueprints which shall set no caching headers
on their responses.
Sets ``Cache-Control``, ``Pragma`` and ``Expires`` headers accordingly
to prevent all client side caching from taking place.
"""
return flask.add_non_caching_response_headers(resp)
def optionsAllowOrigin(request):
"""
Shortcut for request handling for CORS OPTIONS requests to set CORS headers.

View file

@ -322,6 +322,14 @@ def cache_check_response_headers(response):
return False
def add_non_caching_response_headers(response):
response.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "-1"
return response
#~~ access validators for use with tornado

View file

@ -333,9 +333,7 @@ def index():
response.headers["Last-Modified"] = datetime.datetime.now()
if wizard:
response.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "-1"
response = util.flask.add_non_caching_response_headers(response)
return response