feat: add websocket event stream support with sse fallback - #3
Draft
sabbirba wants to merge 1 commit into
Draft
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The WebSocket URL/Host header construction in stream() can generate incorrect endpoints and invalid/mismatched Host headers (notably when BASE_URL includes a path prefix or explicit port).
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds an event-streaming upgrade path to prefer WebSocket delivery for printer jobs, while retaining the existing HTTP SSE stream as a fallback.
Changes:
- Introduces a WebSocket-based stream in
stream()that readsJobmessages and dispatches them to the existinghandle(job)logic. - Keeps the existing SSE
/printerstream path as the fallback when WebSocket connect fails. - Adds
tungstenite(rustls + native roots) and applies a small clippy-driven cleanup increate_lpr_sock.
File summaries
| File | Description |
|---|---|
| src/socket.rs | Minor control-flow cleanup in socket creation error return. |
| src/main.rs | Adds WebSocket streaming path ahead of the existing SSE stream logic. |
| Cargo.toml | Adds tungstenite dependency with rustls TLS configuration. |
| Cargo.lock | Locks new transitive dependencies introduced by tungstenite. |
Review details
- Files reviewed: 3/4 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+296
to
+312
| let mut ws_url = BASE_URL.clone(); | ||
| let _ = ws_url.set_scheme(if BASE_URL.scheme() == "https" { | ||
| "wss" | ||
| } else { | ||
| "ws" | ||
| }); | ||
| ws_url.set_path("printer/ws"); | ||
|
|
||
| let host = ws_url.host_str().unwrap_or_default(); | ||
|
|
||
| let req = tungstenite::http::Request::builder() | ||
| .uri(ws_url.as_str()) | ||
| .header("x-worker-key", WORKER_KEY.as_str()) | ||
| .header("x-worker-ident", WORKER_IDENT.as_str()) | ||
| .header("user-agent", AGENT.as_str()) | ||
| .header("Host", host) | ||
| .header("Connection", "Upgrade") |
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
/printer/wsusingtungstenitewith native TLS.handle(job),claim_job(), andis_online()logic.create_lpr_sock.Verification
cargo fmt --checkpassed.cargo clippy --all-targets --all-features -- -D warningspassed (0 warnings).cargo testpassed.cargo build --releasesucceeded.