-
-
Save wgwz/1c910993554dfd8fb4b559fb449c11ac to your computer and use it in GitHub Desktop.
Demonstrates a Possible Issue with the Flask Test Client
This file contains hidden or 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
from flask import Flask, Blueprint | |
app = Flask(__name__) | |
bp = Blueprint("test", __name__) | |
@bp.route("/test/") | |
def test(): | |
return "TEST" | |
app.register_blueprint(bp, subdomain="test") | |
app.config["PREFERRRED_URL_SCHEME"] = "http" | |
app.config["SERVER_NAME"] = "domain.tld:80" | |
with app.test_client() as c: | |
c.get("/test/", base_url="http://test.domain.tld:80") # Will return 404 | |
c.get("/test/", base_url="http://test.domain.tld") # Will return 404 | |
app.config["SERVER_NAME"] = "domain.tld" | |
with app.test_client() as c: | |
c.get("/test/", base_url="http://test.domain.tld:80") # Will return 200 | |
c.get("/test/", base_url="http://test.domain.tld") # Will return 200 | |
app.config["SERVER_NAME"] = "domain.tld:5000" | |
with app.test_client() as c: | |
c.get("/test/", base_url="http://test.domain.tld:5000") # Will return 200 | |
c.get("/test/", base_url="http://test.domain.tld") # Will return 404 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment