Skip to content

Commit 04d0fea

Browse files
committedDec 16, 2018
adds ProxyFix for Cloud9
1 parent 476650d commit 04d0fea

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed
 

‎setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
package_dir={"": "src"},
1717
packages=["cs50"],
1818
url="https://github.com/cs50/python-cs50",
19-
version="2.4.5"
19+
version="2.5.0"
2020
)

‎src/cs50/flask.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from distutils.version import StrictVersion
2+
from os import getenv
23
from pkg_resources import get_distribution
34

45
from .cs50 import formatException
@@ -9,12 +10,28 @@
910
# Only patch >= 1.0
1011
version = StrictVersion(get_distribution("flask").version)
1112
assert version >= StrictVersion("1.0")
12-
import flask.logging
1313

1414
# Reformat logger's exceptions
1515
# http://flask.pocoo.org/docs/1.0/logging/
1616
# https://docs.python.org/3/library/logging.html#logging.Formatter.formatException
17-
flask.logging.default_handler.formatter.formatException = lambda exc_info: formatException(*exc_info)
17+
try:
18+
import flask.logging
19+
flask.logging.default_handler.formatter.formatException = lambda exc_info: formatException(*exc_info)
20+
except:
21+
pass
22+
23+
# Add support for Cloud9 proxy so that flask.redirect doesn't redirect from HTTPS to HTTP
24+
if getenv("C9_HOSTNAME") and not getenv("IDE_OFFLINE"):
25+
try:
26+
import flask
27+
from werkzeug.contrib.fixers import ProxyFix
28+
before = flask.Flask.__init__
29+
def after(self, *args, **kwargs):
30+
before(self, *args, **kwargs)
31+
self.wsgi_app = ProxyFix(self.wsgi_app)
32+
flask.Flask.__init__ = after
33+
except:
34+
pass
1835

1936
except:
2037
pass

‎tests/redirect/application.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import cs50
2+
from flask import Flask, redirect, render_template
3+
4+
app = Flask(__name__)
5+
6+
@app.route("/")
7+
def index():
8+
return redirect("/foo")
9+
10+
@app.route("/foo")
11+
def foo():
12+
return render_template("foo.html")

‎tests/redirect/templates/foo.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo

0 commit comments

Comments
 (0)