Skip to main content

Module http

Module http 

Source
Expand description

Shared HTTP helpers for the platform clients (pr, issue, release, pipeline, package).

Before 0.7.14, each surface had its own boilerplate around reqwest: build a client, set user-agent, send, parse status, extract a JSON message field for errors. That repeated across ~15 client structs (GitHub × GitLab × Gitea × 5 surfaces).

This module consolidates that into three primitives:

  • make_client — builds the reqwest::blocking::Client with the gitorii user-agent. Use everywhere instead of inline Client::builder().
  • send_json — runs a RequestBuilder, checks status, returns the parsed JSON body. Folds the three-line send/status/parse dance into one call.
  • send_empty — same, but for operations that don’t return a body we care about (cancel, retry, delete).
  • extract_array — turns a JSON value into a &Vec<Value> with a consistent error message when the platform returns a non-array.

The ctx parameter on send_json / send_empty is a free-form label that goes into the error message (e.g. "GitHub", "Gitea (cancel pipeline)"). Callers include the URL there when it helps debugging.

Constants§

USER_AGENT
User-agent string sent on every platform API call.

Functions§

extract_array
Extract the top-level array from a JSON value, or fail with a consistent diagnostic that includes the URL/context.
make_client
Construct the standard blocking HTTP client used by every platform client. Sets a global request timeout so a hung API can’t freeze torii forever. Panics only on a build failure we don’t expect at runtime (would mean reqwest is fundamentally broken).
send_bytes
Send a request and return its body as raw bytes. For artifact downloads (zip / tarball) — the bytes go straight to disk on the caller’s side.
send_empty
Send a request and ignore the response body, only checking status. Used for cancel / retry / delete style operations.
send_json
Send a request, check status, parse JSON. Returns the parsed value on 2xx; on any other status, returns a PlatformApi error including the platform’s own message field when present.
send_text
Send a request and return its body as text. For endpoints like /jobs/{id}/trace or /builds/{id}/log that return plain text instead of JSON — bypasses send_json’s serde_json parse step.