Skip to content

Instantly share code, notes, and snippets.

@CorneliaXaos
Last active December 18, 2019 08:36
Show Gist options
  • Save CorneliaXaos/9e4fa46f442f72fc5bff07ffedace397 to your computer and use it in GitHub Desktop.
Save CorneliaXaos/9e4fa46f442f72fc5bff07ffedace397 to your computer and use it in GitHub Desktop.
Demonstrates a Possible Issue with the Flask Test Client
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