Skip to content

Expose response headers of API calls - #44

Open
lexfrei wants to merge 2 commits into
HenningHolmDE:mainfrom
lexfrei:feat/response-headers
Open

lexfrei wants to merge 2 commits into
HenningHolmDE:mainfrom
lexfrei:feat/response-headers

Conversation

@lexfrei

@lexfrei lexfrei commented Oct 4, 2026 •

Copy link
Copy Markdown

Hetzner reports the rate limit in RateLimit-Limit and RateLimit-Remaining on every response, and this PR lets callers read those headers. Until now the generated client dropped all headers, so a caller learned about the limit only from a 429. In #43 I asked which shape you'd prefer and went with one of them here. If you want the other one, say so and I'll redo it.

The change has two parts:

  • Error responses keep their headers in a new headers field on ResponseContent. It is a Box<HeaderMap>, because without the box the Err variant goes over clippy's result_large_err limit on every operation.
  • Every operation gets an <op>_with_headers function that returns (model, HeaderMap). The existing function calls it and drops the headers, so its signature doesn't change.

This is a breaking change for code that builds ResponseContent with a struct literal or destructures it without ... Everything else compiles as before.

The templates carry the whole change: api.mustache, plus a new api_mod.mustache override. Everything under src/apis is a plain regeneration with generator 7.7.0 and spec d47f7a2, so it doesn't need a line-by-line read. Regenerating main with no template changes gives an empty diff. Regenerating templates.diff also brought in the #[serde(untagged)] hunk from 150a035, which the file was missing.

The new test points the client at a local TCP listener that sends a canned response. It checks the headers on a 200 with a body, on a 204 without one, and on a 429. Clippy reports the same warnings as on main.

Closes #43

Hetzner reports its rate limit state in RateLimit-* headers on every
response, but the generated client discarded all headers, so callers
could only react after a 429.

Error responses now carry the headers in ResponseContent. Each
operation gets an <op>_with_headers sibling that returns the headers
next to the model; the existing function wraps it and keeps its
signature. The headers are boxed to keep the Err variant small.

Adding a field to ResponseContent is a breaking change for code that
builds it with a struct literal or destructures it without `..`.

Regenerating templates.diff also picks up the #[serde(untagged)]
change to model.mustache, which the diff file was missing.

Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose response headers of API calls

1 participant