Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
package_dir={"": "src"},
packages=["cs50"],
url="https://github.com/cs50/python-cs50",
version="2.4.5"
version="2.5.0"
)
22 changes: 20 additions & 2 deletions src/cs50/flask.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from distutils.version import StrictVersion
from os import getenv
from pkg_resources import get_distribution

from .cs50 import formatException
Expand All @@ -9,12 +10,29 @@
# Only patch >= 1.0
version = StrictVersion(get_distribution("flask").version)
assert version >= StrictVersion("1.0")
import flask.logging

# Reformat logger's exceptions
# http://flask.pocoo.org/docs/1.0/logging/
# https://docs.python.org/3/library/logging.html#logging.Formatter.formatException
flask.logging.default_handler.formatter.formatException = lambda exc_info: formatException(*exc_info)
try:
import flask.logging
flask.logging.default_handler.formatter.formatException = lambda exc_info: formatException(*exc_info)
except:
pass

# Add support for Cloud9 proxy so that flask.redirect doesn't redirect from HTTPS to HTTP
# http://stackoverflow.com/a/23504684/5156190
if getenv("C9_PROJECT") == "ide50" and not getenv("IDE_OFFLINE"):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come better, @kzidane?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C9_HOSTNAME is set offline as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that's why we're checking and not getenv("IDE_OFFLINE") too, no?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, in that case we could just check for IDE_OFFLINE really since it's not set online. C9_PROJECT is set to a different value online ("ide50") vs offline ("ide50-offline").

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That'd be different logic. We need the ProxyFix iff using CS50 IDE Online.

try:
import flask
from werkzeug.contrib.fixers import ProxyFix
before = flask.Flask.__init__
def after(self, *args, **kwargs):
before(self, *args, **kwargs)
self.wsgi_app = ProxyFix(self.wsgi_app)
flask.Flask.__init__ = after
except:
pass

except:
pass
12 changes: 12 additions & 0 deletions tests/redirect/application.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import cs50
from flask import Flask, redirect, render_template

app = Flask(__name__)

@app.route("/")
def index():
return redirect("/foo")

@app.route("/foo")
def foo():
return render_template("foo.html")
1 change: 1 addition & 0 deletions tests/redirect/templates/foo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo