Commits

David Larlet committed 5790493

Fixes #105, add an optional setting to the boto storage to produce protocol-relative URLs, thanks @idangazit @pendletongp and @derrickpetzold

  • Participants
  • Parent commits f459336

Comments (0)

Files changed (1)

File storages/backends/s3boto.py

     'application/javascript',
     'application/x-javascript',
 ))
+URL_PROTOCOL = getattr(settings, 'AWS_S3_URL_PROTOCOL', 'http:')
 
+# Backward-compatibility: given the anteriority of the SECURE_URL setting
+# we fall back to https if specified in order to avoid the construction
+# of unsecure urls.
+if SECURE_URLS:
+    URL_PROTOCOL = 'https:'
 
 if IS_GZIPPED:
     from gzip import GzipFile
             encryption=ENCRYPTION,
             custom_domain=CUSTOM_DOMAIN,
             secure_urls=SECURE_URLS,
+            url_protocol=URL_PROTOCOL,
             location=LOCATION,
             file_name_charset=FILE_NAME_CHARSET,
             preload_metadata=PRELOAD_METADATA,
         self.encryption = encryption
         self.custom_domain = custom_domain
         self.secure_urls = secure_urls
+        self.url_protocol = url_protocol
         self.location = location or ''
         self.location = self.location.lstrip('/')
         self.file_name_charset = file_name_charset
     def url(self, name):
         name = self._normalize_name(self._clean_name(name))
         if self.custom_domain:
-            return "%s://%s/%s" % ('https' if self.secure_urls else 'http',
-                                   self.custom_domain, name)
+            return "%s//%s/%s" % (self.url_protocol,
+                                  self.custom_domain, name)
         return self.connection.generate_url(self.querystring_expire,
             method='GET', bucket=self.bucket.name, key=self._encode_name(name),
             query_auth=self.querystring_auth, force_http=not self.secure_urls)