Mercurial > public > sg101
changeset 896:0054a4a88c1c
Remove checking for https availability.
This seems to take quite a while, plus Python doesn't validate the cert, so we
could end up with dodgy sites.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 25 Feb 2015 21:09:41 -0600 |
parents | e7c549e4dbf7 |
children | 49ebeb54990a |
files | core/management/commands/ssl_images.py |
diffstat | 1 files changed, 1 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/core/management/commands/ssl_images.py Thu Feb 19 21:02:21 2015 -0600 +++ b/core/management/commands/ssl_images.py Wed Feb 25 21:09:41 2015 -0600 @@ -8,7 +8,6 @@ """ import base64 import datetime -import httplib import logging from optparse import make_option import os @@ -168,51 +167,13 @@ logger.info("Found URL in cache: %s => %s", src, new_url) return new_url - # It has been observed that at least 2 different services - # serve up the same image on https: with the URL otherwise the same. - # Check to see if the image is available via https first. - new_url = check_https_availability(parsed_url) - if new_url: - url_cache[src] = new_url - return new_url - - # If none of the above worked, try to download and upload to our S3 bucket + # Try to download and upload to our S3 bucket new_url = save_image_to_cloud(src) if new_url: url_cache[src] = new_url return new_url -def check_https_availability(parsed_url): - """Given a urlparse.urlparse() result, perform a HEAD request over https - using the same net location and path. If we get a response that indicates an - image is available, return the url of the image over https. Otherwise return - None. - """ - logger.info("Checking https availability for %s", parsed_url.geturl()) - con = httplib.HTTPSConnection(parsed_url.netloc) - try: - con.request('HEAD', parsed_url.path) - except (httplib.HTTPException, socket.timeout) as ex: - logger.info("https HEAD request failed: %s", ex) - return None - - content_type = None - response = con.getresponse() - if response.status == 200: - content_type = response.getheader('content-type') - if content_type: - parts = content_type.split('/') - if len(parts) >= 2 and parts[0] == 'image': - url = urlparse.urlunparse(('https', ) + parsed_url[1:]) - logger.info("Image is available at %s", url) - return url - - logger.info('https HEAD request failed; status = %d, content-type = %s', - response.status, content_type) - return None - - def save_image_to_cloud(src): """Downloads an image at a given source URL. Uploads it to cloud storage.