Esc

parse_status

procedureextensionsince 0.36.1Source
  • macOS: parse_status works on macOS
  • Linux: parse_status works on Linux
  • Windows: parse_status works on Windows
  • Wasm: parse_status works on Wasm

Parses authoritative final status; HTTP mapping applies only when grpc-status is missing or invalid. Repeated status fields are a protocol failure. .

Signature

parse_status :: (
    fields: [] Http.Header_Field,
    http_status: int,
    limit := 64 * 1024
) -> Status
Example↗
Http :: #import "Extensions/Http";

main :: () {
    fields := Http.Header_Field.[
        .{ name = "grpc-status", value = "5" },
        .{ name = "grpc-message", value = "no%20such%20user" },
    ];
    status := parse_status(fields, 200);
    defer free_status(*status);
    assert(status.code == .NOT_FOUND && status.message == "no such user");

    missing := parse_status(.[], 503); // no grpc-status: the HTTP status decides
    defer free_status(*missing);
    assert(missing.code == .UNAVAILABLE);
}

See also