diff options
author | Marian Sigler <m@qjym.de> | 2012-10-06 16:40:24 +0200 |
---|---|---|
committer | Marian Sigler <m@qjym.de> | 2012-10-06 16:40:35 +0200 |
commit | b52de923cbb794b8dbc4d94c60c38088e26d95b5 (patch) | |
tree | ee2abbf99c8ba4815a1fefcde51f267a3649b81c /utils.py | |
parent | f1683aaf4b02721c26e68723fcbaebb536aac26a (diff) | |
download | web-b52de923cbb794b8dbc4d94c60c38088e26d95b5.tar.gz web-b52de923cbb794b8dbc4d94c60c38088e26d95b5.tar.bz2 web-b52de923cbb794b8dbc4d94c60c38088e26d95b5.zip |
Make external urls always with https
Diffstat (limited to 'utils.py')
-rw-r--r-- | utils.py | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -9,7 +9,8 @@ from base64 import urlsafe_b64encode, urlsafe_b64decode from Crypto.Cipher import AES from email.mime.text import MIMEText from functools import wraps -from flask import current_app, flash, g, redirect, render_template, request, session, url_for +from flask import current_app, flash, g, redirect, render_template, request, session +from flask import url_for as flask_url_for from flask.ext.wtf import ValidationError from hashlib import sha1 from random import randint @@ -227,3 +228,13 @@ class NotRegexp(Regexp): self.message = field.gettext(u'Invalid input.') raise ValidationError(self.message) + + +def url_for(endpoint, **values): + """Wrap `flask.url_for` so that it always returns https links""" + #XXX: Drop this in favor of config.PREFERRED_URL_SCHEME when we require Flask 0.9 + u = flask_url_for(endpoint, **values) + if '_external' in values and u.startswith('http://'): + return 'https://' + u[7:] + else: + return u |