refactor: extract GatewayHTTPHandler from WebSocketChannel#4115
Draft
chengyongru wants to merge 7 commits into
Draft
refactor: extract GatewayHTTPHandler from WebSocketChannel#4115chengyongru wants to merge 7 commits into
chengyongru wants to merge 7 commits into
Conversation
f2cc227 to
b4ac502
Compare
Extract all HTTP route handling (bootstrap, sessions, settings, media, commands, sidebar state, static serving, token management) into a new GatewayHTTPHandler class in nanobot/channels/ws_http.py. WebSocketChannel is reduced from 1907 to 1372 lines (-28%), retaining only WebSocket connection management and message dispatch. No behavior change. 3730 tests pass, 0 failures. Shared HTTP utility functions (path parsing, response builders, auth helpers) now live in ws_http.py with websocket.py importing from there, avoiding circular dependencies. Backwards-compat property aliases on WebSocketChannel ensure existing tests continue to work without modification.
4800fd9 to
74560fa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extract all HTTP route handling from
WebSocketChannelinto a newGatewayHTTPHandlerclass innanobot/channels/ws_http.py.This is the first step toward decoupling WebUI, WebSocket transport, and AgentLoop — and a prerequisite for future hot-reload capabilities.
What changed
New file:
nanobot/channels/ws_http.py—GatewayHTTPHandler(731 lines)WebUISettingsRouterModified:
nanobot/channels/websocket.py— 1907 → 1372 lines (-28%)_dispatch_http()now only handles WS upgrade directly, delegates everything else toGatewayHTTPHandlersend()delegates media helpers to handlerShared utilities: HTTP helper functions (
_parse_query,_http_error,_bearer_token, etc.) moved tows_http.pywithwebsocket.pyimporting from thereWhat didn't change
Test plan
pytest tests/channels/— 204 passedpytest tests/— 3730 passed, 27 skipped, 0 failedruff check— clean