Created
April 6, 2011 12:24
-
-
Save peterbe/905558 to your computer and use it in GitHub Desktop.
Mixing class for dealing with HTTPS URL related stuff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HTTPSMixin(object): | |
def is_secure(self): | |
return self.request.headers.get('X-Scheme') == 'https' | |
def httpify_url(self, url=None): | |
url = url if url else self.request.full_url() | |
if url.startswith('/'): | |
parsed = urlparse(self.request.full_url()) | |
return 'http://%s%s' % (parsed.netloc, url) | |
else: | |
return url.replace('https://', 'http://') | |
def httpsify_url(self, url=None): | |
url = url if url else self.request.full_url() | |
if url.startswith('/'): | |
parsed = urlparse(self.request.full_url()) | |
return 'https://%s%s' % (parsed.netloc, url) | |
else: | |
return url.replace('http://', 'https://') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment