| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using Invercargill;
- using Invercargill.DataStructures;
- using Astralis;
- namespace Statum {
- /**
- * Helpers for rendering Statum directive responses.
- */
- public class StatumDirectives : Object {
- /** The content type that distinguishes a Statum directive response. */
- public const string CONTENT_TYPE = "application/vnd.statum+json";
- /**
- * Builds the short-circuit response an endpoint returns when the request
- * carried slots the server does not have in memory: a `transmit(retry)`
- * per missing key (plus an `invalidate` per untrustworthy frame
- * signature). The client re-sends the frames to the slot post endpoint,
- * drops any that fail verification, then re-issues the original request.
- */
- public static HttpResult transmit_result(Lot<string> transmit_keys, Lot<string>? invalid_signatures = null) throws GLib.Error {
- var directives = new Series<Model.DirectiveDto>();
- foreach (var key in transmit_keys) {
- directives.add(new Model.TransmitDirectiveDto.with(key, true));
- }
- return to_result(directives, invalid_signatures);
- }
- /**
- * Renders a lot of directives as the JSON array response served by every
- * directive-returning endpoint, with the Statum content type and
- * `Cache-Control: no-store`.
- *
- * Any invalid frame `signature`s are appended as `invalidate` directives
- * so the client drops slots whose frames the server could not trust.
- */
- public static HttpResult to_result(Lot<Model.DirectiveDto> directives, Lot<string>? invalid_signatures = null) throws GLib.Error {
- var rendered = new Series<Model.DirectiveDto>();
- foreach (var directive in directives) {
- rendered.add(directive);
- }
- if (invalid_signatures != null) {
- foreach (var signature in (!)invalid_signatures) {
- rendered.add(new Model.InvalidateDirectiveDto.with_signature(signature));
- }
- }
- var json = Model.DirectiveDto.serialize_array(rendered);
- var result = new HttpStringResult(json.stringify());
- result.set_header("Content-Type", CONTENT_TYPE);
- result.set_header("Cache-Control", "no-store");
- return result;
- }
- }
- }
|