Skip to content

Instantly share code, notes, and snippets.

@wgwz
Forked from CorneliaXaos/issue.py
Created July 22, 2016 22:54
Show Gist options
  • Save wgwz/1c910993554dfd8fb4b559fb449c11ac to your computer and use it in GitHub Desktop.
Save wgwz/1c910993554dfd8fb4b559fb449c11ac 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