Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send 404, fix 403 being sent on page not found #425

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions routers/static_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import gooey_gui as gui
import requests
from fastapi import HTTPException
from starlette.requests import Request
from starlette.responses import (
Response,
RedirectResponse,
HTMLResponse,
PlainTextResponse,
Expand Down Expand Up @@ -38,8 +38,11 @@ def serve_static_file(request: Request, path: str):

# if the path has no extension, try to serve a .html file
if not os.path.splitext(gcs_path)[1]:
html_url = bucket.blob(gcs_path + ".html").public_url
r = requests.get(html_url)
html_blob = bucket.blob(gcs_path + ".html")
if not html_blob.exists():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you wanna do this, because it means a static file that doesn't have an extension but is NOT an HTML file cannot be served at all

raise HTTPException(status_code=404)

r = requests.get(html_blob.public_url)
if r.ok:
html = r.content.decode()
# replace sign in button with user's name if logged in
Expand All @@ -51,12 +54,13 @@ def serve_static_file(request: Request, path: str):
)
return HTMLResponse(html, status_code=r.status_code)

url = bucket.blob(gcs_path).public_url
r = requests.head(url)
if r.ok:
return RedirectResponse(url, status_code=HTTP_308_PERMANENT_REDIRECT)
blob = bucket.blob(gcs_path)
if blob.exists():
return RedirectResponse(
blob.public_url, status_code=HTTP_308_PERMANENT_REDIRECT
)

return Response(status_code=r.status_code)
raise HTTPException(status_code=404)


@gui.route(app, "/internal/webflow-upload/")
Expand Down