Skip to content

Fix 404 on bookmarked URLs with query strings#125

Open
fheinent wants to merge 1 commit into
phuryn:mainfrom
fheinent:fix/handler-query-params
Open

Fix 404 on bookmarked URLs with query strings#125
fheinent wants to merge 1 commit into
phuryn:mainfrom
fheinent:fix/handler-query-params

Conversation

@fheinent
Copy link
Copy Markdown

What

DashboardHandler.do_GET matches self.path against literal strings (/, /index.html, /api/data). self.path includes the query string, so URLs like /?range=all — the format the dashboard itself writes via history.replaceState for bookmarkable range/model filters — fall through to the 404 branch on hard-refresh or bookmark navigation.

Repro

python3 cli.py dashboard
curl -o /dev/null -w "%{http_code}\n" http://localhost:8080/            # 200
curl -o /dev/null -w "%{http_code}\n" http://localhost:8080/?range=all  # 404 (bug)

Fix

Split off the query string with urlparse(self.path).path before matching. Apply in both do_GET and do_POST. No new dependency — urllib.parse is stdlib.

Test plan (smoke-tested locally)

Request Before After
GET / 200 200
GET /?range=all 404 200
GET /?range=7d 404 200
GET /api/data 200 200
GET /api/data?x=1 404 200
GET /nonexistent 404 404

`DashboardHandler.do_GET` matched `self.path` against the literal strings
`/`, `/index.html`, and `/api/data`. `self.path` includes the query
string, so any URL like `/?range=all` (the format the dashboard itself
writes via `history.replaceState` for bookmarkable range/model filters)
fell through to the 404 branch on hard-refresh or bookmark navigation.

Routes don't depend on query parameters here, so split the path
component with `urlparse(self.path).path` before matching. Apply the
same in `do_POST` for symmetry. No new dependency — `urllib.parse` is
stdlib.

Smoke-tested locally:
- GET /                -> 200 (was 200)
- GET /?range=all      -> 200 (was 404)
- GET /api/data        -> 200 (was 200)
- GET /api/data?x=1    -> 200 (was 404)
- GET /nonexistent     -> 404 (was 404)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant