Fix PhantomJS by always using the local copy of CDN files, and making sure to specify TLS (instead of the default SSLv3, which is now deprecated)

This commit is contained in:
Joseph Schorr 2014-11-25 15:32:10 -05:00
parent b8e9f2d1fa
commit 3a935822fc
2 changed files with 20 additions and 3 deletions

View file

@ -170,8 +170,12 @@ def render_page_template(name, **kwargs):
main_scripts = ['dist/quay-frontend.min.js']
cache_buster = SAVED_CACHE_STRING
external_styles = get_external_css(local=not app.config.get('USE_CDN', True))
external_scripts = get_external_javascript(local=not app.config.get('USE_CDN', True))
use_cdn = app.config.get('USE_CDN', True)
if request.args.get('use_cdn') is not None:
use_cdn = request.args.get('use_cdn') == 'true'
external_styles = get_external_css(local=not use_cdn)
external_scripts = get_external_javascript(local=not use_cdn)
def get_oauth_config():
oauth_config = {}

View file

@ -1,16 +1,29 @@
import subprocess
import logging
from urllib import urlencode
from urlparse import parse_qs, urlsplit, urlunsplit
from bs4 import BeautifulSoup
logger = logging.getLogger(__name__)
def set_query_parameter(url, param_name, param_value):
# From: http://stackoverflow.com/questions/4293460/how-to-add-custom-parameters-to-an-url-query-string-with-python
scheme, netloc, path, query_string, fragment = urlsplit(url)
query_params = parse_qs(query_string)
query_params[param_name] = [param_value]
new_query_string = urlencode(query_params, doseq=True)
return urlunsplit((scheme, netloc, path, new_query_string, fragment))
def render_snapshot(url):
logger.info('Snapshotting url: %s' % url)
url = set_query_parameter(url, 'use_cdn', False)
out_html = subprocess.check_output(['phantomjs', '--ignore-ssl-errors=yes',
'--disk-cache=yes',
'--disk-cache=yes', '--ssl-protocol=tlsv1',
'util/phantomjs-runner.js', url])
if not out_html or out_html.strip() == 'Not Found':