feat(proxy): websocket proxy support user-specified port; http proxy support all methods#666
Merged
StephenRi merged 34 commits intoalibaba:masterfrom Mar 27, 2026
Merged
Conversation
StephenRi
reviewed
Mar 25, 2026
…access" This reverts commit ddf9d13.
…tps redirect loop
…ep in message forwarding
receive_text() and receive_bytes() share the same ASGI message queue. When receive_text() consumed a binary frame and raised KeyError, the frame was permanently lost — the fallback receive_bytes() read the NEXT message instead. This silently dropped ~50% of binary frames, breaking VNC/noVNC and other binary WebSocket protocols. Switch to raw receive() which reads exactly once per message, then dispatches by content type. Also removes per-frame logger.info calls that printed full binary content (severe perf hit for VNC traffic) and fixes websockets v15+ compat (ConnectionClosed import path). Made-with: Cursor
349476d to
cc5ff2b
Compare
- Remove HTTP routes: /sandboxes/{id}/proxy/port/{port}/{path}
- Remove WS routes: /sandboxes/{id}/proxy/port/{port}/ws/{path}
- Add generic WS route: /sandboxes/{id}/proxy/{path}
- Port now only specified via rock_target_port query parameter
- Update tests to verify new behavior
f406cce to
e386710
Compare
- Add HTTP routes: /sandboxes/{sandbox_id}/proxy/vnc/{path}
- Add WebSocket route: /sandboxes/{sandbox_id}/proxy/vnc/{path}
- Fixed port forwarding to 8006 for all VNC requests
- Ignore rock_target_port query parameter for VNC routes
- Add comprehensive unit tests for HTTP and WebSocket VNC proxy
- Add spec, plan, and task documentation to docs/_specs/vnc-proxy/
e386710 to
4c9e739
Compare
- Add X-ROCK-Target-Port header support for HTTP proxy - Add X-ROCK-Target-Port header support for WebSocket proxy - Return 400 error when both header and query param are specified - Add resolve_target_port helper function - Add comprehensive tests for header port support
- Document X-ROCK-Target-Port header for WebSocket proxy - Document X-ROCK-Target-Port header for HTTP proxy - Add usage examples with header - Document conflict error when both header and query param are specified
- Restore /sandboxes/{sandbox_id}/proxy/port/{port}/{path} routes (backward compatible)
- Restore /sandboxes/{id}/proxy/port/{port}/ws/{path} WebSocket routes
- Fix VNC proxy: add proxy_prefix and query_string parameters
- This fixes Location header rewriting for noVNC callbacks
- Add resolve_target_port_from_ws for WebSocket port resolution - Both HTTP and WebSocket proxy extract port from path (port/8006/...) - Return 400 error when port specified via multiple sources - Update tests to reflect new behavior
FastAPI matches routes by registration order. VNC WebSocket route must be
registered before generic /proxy/{path:path} to match correctly.
Shorter URL path for VNC access:
- HTTP: /sandboxes/{id}/vnc/{path}
- WebSocket: /sandboxes/{id}/vnc/{path}
Issac-Newton
pushed a commit
that referenced
this pull request
Mar 27, 2026
Shortened VNC route path:
HTTP: /sandboxes/{id}/vnc/{path}
WebSocket: /sandboxes/{id}/vnc/{path}
Moved from /proxy/vnc to /vnc for cleaner, more concise URLs.
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
portquery param to/sandboxes/{id}/proxy/ws[/{path}]; connects tows://{host_ip}:{port}when specified, falls back to mapped SERVER port (8080) when omitted. Invalid ports rejected with WS close code 1008./sandboxes/{sandbox_id}/proxy[/{path}]from POST-only toapi_routesupporting GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS; method is transparently forwarded to the sandbox service.portquery param; connects tohttp://{host_ip}:{port}when specified, falls back to mapped SERVER port (8080) when omitted./sandboxes/{id}/proxy/port/{port}[/{path}](HTTP) and/sandboxes/{id}/proxy/port/{port}/ws[/{path}](WS) routes; embeds port in path so browser relative-path requests (JS/CSS/images) inherit the port automatically — enables VNC/Jupyter browser access.Changes
rock/admin/entrypoints/sandbox_proxy_api.py: addportquery param to WS and HTTP proxy endpoints; replace@postwith@api_routefor HTTP proxy; add path-based port routes registered before{path:path}to avoid FastAPI matching ambiguityrock/sandbox/service/sandbox_proxy_service.py: addportparam towebsocket_proxy/get_sandbox_websocket_url/http_proxy; renamepost_proxy→http_proxywithmethodandportparamstests/unit/sandbox/test_proxy_enhancements.py: new unit tests (28 cases)tests/unit/sandbox/test_sandbox_proxy_router.py: update to reflect renamed service methoddocs/_specs/proxy-enhancements/: requirement / interface / implementation spec docsTest Plan
closes #665