Skip to content

Commit 77519d5

Browse files
glasntdandhlee
andauthored
Correct URL parsing logic (GoogleCloudPlatform#7530)
Co-authored-by: Dan Lee <[email protected]>
1 parent 89bb325 commit 77519d5

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

appengine/standard_python3/django/app.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ runtime: python39
2020

2121
env_variables:
2222
# This setting is used in settings.py to configure your ALLOWED_HOSTS
23-
# APPENGINE_URL: https://PROJECT_ID.uc.r.appspot.com
23+
# APPENGINE_URL: PROJECT_ID.uc.r.appspot.com
2424

2525
handlers:
2626
# This configures Google App Engine to serve the files in the app's static

appengine/standard_python3/django/mysite/settings.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,12 @@
6767
# to App Engine. This code takes the URL and converts it to both these settings formats.
6868
APPENGINE_URL = env("APPENGINE_URL", default=None)
6969
if APPENGINE_URL:
70-
# Ensure the HTTPS is in the URL before it's used.
71-
APPENGINE_URL = urlparse(APPENGINE_URL, "https").geturl()
70+
# Ensure a scheme is present in the URL before it's processed.
71+
if not urlparse(APPENGINE_URL).scheme:
72+
APPENGINE_URL = f"https://{APPENGINE_URL}"
7273

73-
ALLOWED_HOSTS = [APPENGINE_URL]
74-
CSRF_TRUSTED_ORIGINS = [urlparse(APPENGINE_URL).netloc]
74+
ALLOWED_HOSTS = [urlparse(APPENGINE_URL).netloc]
75+
CSRF_TRUSTED_ORIGINS = [APPENGINE_URL]
7576
SECURE_SSL_REDIRECT = True
7677
else:
7778
ALLOWED_HOSTS = ["*"]

0 commit comments

Comments
 (0)