Skip to content

Commit

Permalink
fix: check the x-forwarded-proto header for setting the scheme of an …
Browse files Browse the repository at this point in the history
…url created with url_for
  • Loading branch information
zumuta committed Dec 8, 2024
1 parent 0fb6fad commit 555dd35
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
6 changes: 5 additions & 1 deletion backend/src/kwai/frontend/apps/_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ async def get_app(
if asset_file_path is not None:
return EtagFileResponse(asset_file_path)

url = request.url_for(APP_NAME, path="")
if "x-forwarded-proto" in request.headers:
url = url.replace(scheme=request.headers["x-forwarded-proto"])

return templates.TemplateResponse(
"index.jinja2",
{
"application": {
"name": APP_NAME,
"url": str(request.url_for(APP_NAME, path="")),
"url": str(url),
},
"request": request,
"vite": vite,
Expand Down
6 changes: 5 additions & 1 deletion backend/src/kwai/frontend/apps/_author.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ async def get_app(
if asset_file_path is not None:
return EtagFileResponse(asset_file_path)

url = request.url_for(APP_NAME, path="")
if "x-forwarded-proto" in request.headers:
url = url.replace(scheme=request.headers["x-forwarded-proto"])

return templates.TemplateResponse(
"index.jinja2",
{
"application": {
"name": APP_NAME,
"url": str(request.url_for(APP_NAME, path="")),
"url": str(url),
},
"request": request,
"vite": vite,
Expand Down
6 changes: 5 additions & 1 deletion backend/src/kwai/frontend/apps/_club.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ async def get_app(
if asset_file_path is not None:
return EtagFileResponse(asset_file_path)

url = request.url_for(APP_NAME, path="")
if "x-forwarded-proto" in request.headers:
url = url.replace(scheme=request.headers["x-forwarded-proto"])

return templates.TemplateResponse(
"index.jinja2",
{
"application": {
"name": APP_NAME,
"url": str(request.url_for(APP_NAME, path="")),
"url": str(url),
},
"request": request,
"vite": vite,
Expand Down
6 changes: 5 additions & 1 deletion backend/src/kwai/frontend/apps/_coach.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ async def get_app(
if asset_file_path is not None:
return EtagFileResponse(asset_file_path)

url = request.url_for(APP_NAME, path="")
if "x-forwarded-proto" in request.headers:
url = url.replace(scheme=request.headers["x-forwarded-proto"])

return templates.TemplateResponse(
"index.jinja2",
{
"application": {
"name": APP_NAME,
"url": str(request.url_for(APP_NAME, path="")),
"url": str(url),
},
"request": request,
"vite": vite,
Expand Down
6 changes: 5 additions & 1 deletion backend/src/kwai/frontend/apps/_portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ async def get_app(
if asset_file_path is not None:
return EtagFileResponse(asset_file_path)

url = request.url_for(APP_NAME, path="")
if "x-forwarded-proto" in request.headers:
url = url.replace(scheme=request.headers["x-forwarded-proto"])

return templates.TemplateResponse(
"index.jinja2",
{
"application": {
"name": APP_NAME,
"url": str(request.url_for(APP_NAME, path="")),
"url": str(url),
},
"request": request,
"vite": vite,
Expand Down

0 comments on commit 555dd35

Please sign in to comment.