|
@@ -20,6 +20,7 @@ from __future__ import absolute_import
|
|
|
import inspect
|
|
import inspect
|
|
|
import json
|
|
import json
|
|
|
import logging
|
|
import logging
|
|
|
|
|
+import mimetypes
|
|
|
import os.path
|
|
import os.path
|
|
|
import re
|
|
import re
|
|
|
import tempfile
|
|
import tempfile
|
|
@@ -683,4 +684,22 @@ class ContentSecurityPolicyMiddleware(object):
|
|
|
if self.secure_content_security_policy and not 'Content-Security-Policy' in response:
|
|
if self.secure_content_security_policy and not 'Content-Security-Policy' in response:
|
|
|
response["Content-Security-Policy"] = self.secure_content_security_policy
|
|
response["Content-Security-Policy"] = self.secure_content_security_policy
|
|
|
|
|
|
|
|
- return response
|
|
|
|
|
|
|
+ return response
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+class MimeTypeJSFileFixStreamingMiddleware(object):
|
|
|
|
|
+ """
|
|
|
|
|
+ Middleware to detect and fix ".js" mimetype. SLES 11SP4 as example OS which detect js file
|
|
|
|
|
+ as "text/x-js" and if strict X-Content-Type-Options=nosniff is set then browser fails to
|
|
|
|
|
+ execute javascript file.
|
|
|
|
|
+ """
|
|
|
|
|
+ def __init__(self):
|
|
|
|
|
+ jsmimetypes = ['application/javascript', 'application/ecmascript']
|
|
|
|
|
+ if mimetypes.guess_type("dummy.js")[0] in jsmimetypes:
|
|
|
|
|
+ LOG.info('Unloading MimeTypeJSFileFixStreamingMiddleware')
|
|
|
|
|
+ raise exceptions.MiddlewareNotUsed
|
|
|
|
|
+
|
|
|
|
|
+ def process_response(self, request, response):
|
|
|
|
|
+ if request.path_info.endswith('.js'):
|
|
|
|
|
+ response['Content-Type'] = "application/javascript"
|
|
|
|
|
+ return response
|