import {
"q2316367743/moonhttp/headers",
}| 方法 | 说明 |
|---|---|
| Headers::new() | 空集合 |
| Headers::from_pairs([("A", "1")]) | 从数组构造 |
| Headers::get(name) | 取值,String? |
| Headers::has(name) | 是否存在 |
| Headers::set(name, value) | 写入 / 覆盖,返回新实例 |
| Headers::set_if_absent(name, value) | 只在缺失时写入(补默认头用它) |
| Headers::remove(name) | 删除,返回新实例 |
| Headers::merge(other) | 合并,other 的同名头覆盖本实例 |
| Headers::entries() | 全部 (名, 值),顺序即写入顺序 |
| Headers::length() / is_empty() | 数量判断 |
| Headers::to_string() / equal / not_equal / repr | 输出与比较(Show / Eq / Debug) |
let headers = @headers.Headers::new()
.set("Content-Type", "application/json")
.set_if_absent("Accept", "application/json, text/plain, */*")
headers.get("content-type") // Some("application/json")
headers.has("ACCEPT") // truepub struct Headers {
// private fields
}Install
Download zipaxios 风格的 MoonBit HTTP 客户端:实例与配置合并、四种请求体形态、流式与 SSE、自动重定向
Dependencies