magpie icon indicating copy to clipboard operation
magpie copied to clipboard

provider: a Balance URL's POST can't send a body, so an endpoint that asks in JSON can't be read (branch ready)

Open Niko-Wu opened this issue 5 days ago • 0 comments

What is missing

A custom provider's Balance URL is asked with GET, or with POST since #2368 — but that POST goes with no body (balance.go, NewRequestWithContext(..., nil)). An endpoint that reads its parameters from a JSON body and not the URL (a relay, or an internal gateway that wants the caller's id posted to answer with what is left) can't be asked at all: GET is refused by it, and the bodyless POST gets a 400.

A concrete case: a company gateway where POST /internal/model-gateway/access takes {"staff_id":["…"]} and answers {"result":[{"remaining":100}]}. magpie can reach it (method POST works, headers can carry anything), but it has nowhere to put the body.

Proposal

A BalanceBody on the provider, sent as the POST's body with Content-Type: application/json, {key} in it replaced as in the URL and headers (so one body serves every key). A body set with any method but POST is refused when the balance is read, as an unknown method is, rather than sent without it. balance.body= on the command line; a Balance body field in the editor's More endpoints fold.

The editor's field ships as a lazy module (balancebody.js, as balfound.js is) so the core script budget rises only by the import line and the three propagations, 267 bytes.

Branch

https://github.com/Niko-Wu/magpie/tree/feat/balance-body — one commit on top of upstream main (v0.1.5273), tests red-on-old for the new behaviour:

  • TestBalanceBody (internal/provider): the body sent with Content-Type JSON, {key} replaced, a body with GET refused with nothing asked, POST with no body unchanged
  • TestProviderSetBalanceMethod extended for balance.body= set and emptied
  • balance-method.test.cjs extended: the body goes with Check balance and with Save, in both engines and every language
  • balance tests, GUI provider tests, core budget, i18n-keys: all green; go build ./... and go vet clean on macOS

Niko-Wu avatar Dec 01 '26 09:12 Niko-Wu