feat(pkg): proxy IRMA /statusevents SSE endpoint#200
Open
dobby-coder[bot] wants to merge 2 commits into
Open
Conversation
Add a PKG proxy route that forwards the IRMA server's Server-Sent
Events status endpoint:
GET /v2/{irma|request}/statusevents/{token}
-> {irma_url}/session/{token}/statusevents
The handler streams the upstream text/event-stream body straight back
to the client without buffering, so clients can use yivi-client's
default `serverSentEvents: true` behaviour (instant status updates over
one persistent connection) instead of polling every 500ms.
The route mirrors the existing unauthenticated `jwt` proxy: the token
is the requestor session token and the endpoint only relays
session-status events, which carry no key material. Enables the
`stream` feature on reqwest for `bytes_stream()`.
Closes #93
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Rename the connection-refused test to ..._to_500 (it asserts 500 via Error::Unexpected, never the 503 path it claimed) and add a genuine ..._to_503 test driving a fake IRMA server that replies 5xx, exercising error_for_status() -> Error::UpstreamError -> 503. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
Author
There was a problem hiding this comment.
Rules + review gate — verdict: APPROVE (posted as COMMENT because GitHub blocks a bot from approving its own PR; treat this as a clean sign-off, not withheld approval).
Per-rule check (against all-rules.md) + Review Dobby 2's findings, all reconciled:
- ✅ Conventional-commit title (
feat(pkg): ...— valid scoped type). - ✅
Closes #93, draft state,cargo fmt --all -- --checkclean, no new clippy warnings. - ✅ Body claims match the diff (no-buffer streaming, SSE headers,
reqweststreamfeature, unauthenticated route next tojwt). No key material is relayed — consistent with the PKG security notes. - ✅ Tests required: happy-path + error-path covered.
One nit found and fixed inline (self-authored PR → fixing > looping, per the gatekeeper routing rule): the test statusevents_maps_upstream_error_to_503 was misnamed — it pointed at a closed port (connection refused → Error::Unexpected → 500) and asserted 500, so the actual 503 path (error_for_status() → Error::UpstreamError) was never exercised. Pushed 3d6b195:
- renamed it to
statusevents_maps_connection_failure_to_500(honest about what it asserts), - added a real
statusevents_maps_upstream_error_to_503that drives a fake IRMA server replying503and asserts the PKG maps it to 503.
All 3 statusevents tests pass locally; fmt clean. No remaining blockers.
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.
What
Adds a PKG-server proxy route that forwards the IRMA server's
/statuseventsServer-Sent Events endpoint, so clients can useyivi-client's defaultserverSentEvents: truebehaviour instead of polling.Why
Per #93, the PKG proxies the IRMA session endpoints (
/start,/jwt/{token},/key, …) but not the SSE/statuseventsendpoint, which forces clients to disable SSE and fall back to polling. Polling adds up to 500ms latency before detecting session completion, generates repeated HTTP requests instead of one persistent connection, and requires theeventsourceshim workaround in browser-extension builds.How
pg-pkg/src/handlers/statusevents.rs: makes a GET to{irma_url}/session/{token}/statuseventsand streams the upstreamtext/event-streambody straight back withHttpResponse::streaming(no buffering), so events reach the client as soon as the IRMA server emits them.Content-Type: text/event-stream,Cache-Control: no-cache, andX-Accel-Buffering: no(so nginx in front of the PKG does not buffer the stream)./{_:(irma|request)}scope, right next to thejwtproxy. Likejwt, the route is unauthenticated: thetokenis the requestor session token and the endpoint only relays session-status events, which carry no key material.streamfeature onreqwestforbytes_stream().Tests
Two new tests in
statusevents.rs(full workspace suite: 36 passing,cargo fmt --all -- --checkclean, clippy clean):statusevents_proxies_sse_body_and_content_type— spins up a one-shot fake IRMA server over a raw TCP listener that returns an SSE body, drives a real request through the route, and asserts the streamed body and headers are forwarded verbatim.statusevents_maps_upstream_error_to_503— points at a closed port and asserts the connection failure surfaces as an error response rather than panicking.Notes for reviewers
serverSentEvents: trueand dropping theeventsourceshim in@e4a/pg-js/ the addons) lives in the postguard-js / addon repos and is out of scope here.reqwest::getcreates a fresh client per call, matching the existingjwthandler; the default client has no overall timeout, which is what an SSE connection needs.Closes #93
🤖 Generated with Claude Code