Protobuf beside JSON in ipx's, the directory's and ipx-play's APIs (#465); ipx's build touches crates/play (#466)
A client sending Accept: application/x-protobuf gets protobuf, and one sending Content-Type: application/x-protobuf may send its body so; JSON stays the default, so the page, the TUI and older iOS builds see nothing new. ipx's own calls to the directory and ipx-play now go in protobuf. The handlers are untouched. A new crate, ipx-wire, holds the .proto files (compiled by protox in build.rs, so no protoc anywhere) and one layer, negotiate, that converts JSON at the edge through prost-reflect, by a table of each route's messages. Writing prost structs beside every serde one would have doubled each type and every handler. Protobuf cannot tell absent from empty or from null, and the PATCH bodies depend on that: an Option<Vec> left out leaves the list, an empty one clears it, and null clears a folder. So a list in a body is a one-field message (absent or present), and null-to-clear is a google.protobuf.Value. Numbers in a Value come back whole, or 3.0 would not read as a usize. Debug builds convert every JSON answer strictly and answer 500 for a field missing from the .proto or a route missing from a table; the cargo tests and the browser suite (125 tests) ran clean that way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -208,6 +208,15 @@ else a `401`. A feed's items and files (its entries, `download-latest`, `/api/en
|
||||
| `GET /api/logs` | admin-only; the ring buffer, with a sequence cursor |
|
||||
| `GET /media/{id}` | the file, with Range support so seeking works |
|
||||
|
||||
Every route that takes or answers JSON also speaks protobuf (#465): `Content-Type:
|
||||
application/x-protobuf` for a body, `Accept: application/x-protobuf` for an answer, JSON
|
||||
otherwise. The messages are in `crates/wire/proto/` (ipx, directory and play), and the handlers do
|
||||
not know: `ipx_wire::negotiate`, a layer on each service's routes, converts the JSON at the edge
|
||||
by its table of each route's messages (`WIRE` in `web.rs`, `api.rs` and play's `lib.rs`). A route
|
||||
added to a router goes in its table. Debug builds convert every JSON answer strictly, so the cargo
|
||||
tests and the browser suite answer `500` for a field missing from the `.proto` or a route missing
|
||||
from the table. Errors stay JSON.
|
||||
|
||||
Show notes are feed-supplied HTML from an untrusted source, sanitized with `ammonia` server-side
|
||||
before they reach the page.
|
||||
|
||||
|
||||
@@ -162,6 +162,9 @@ blocks it, so no snapshot brings it back.
|
||||
| `DELETE /v1/instances/{name}` | rwa | drop one token's snapshot, its counts with it |
|
||||
| `POST /v1/feeds/{id}/refresh` | rwa | fetch the feed now, answering with its page |
|
||||
|
||||
Each also speaks protobuf, by `Accept` and `Content-Type: application/x-protobuf` (#465), in the
|
||||
messages of `crates/wire/proto/directory.proto`; ipx asks for it.
|
||||
|
||||
A feed's `id` is the first 64 bits of the SHA-256 of its address, normalised (scheme and host in
|
||||
lower case, no default port or fragment), so every server arrives at the same id. `subscribers`
|
||||
is the sum over every token's latest snapshot. A feed is listed once the directory has read it as
|
||||
|
||||
Reference in New Issue
Block a user