- HTTP Headers for the JavaScript target: https://developer.mozilla.org/en-US/docs/Web/API/Headers
Example: cmd: -r:off
import std/jsheaders block: let header: Headers = newHeaders() header.add("key", "value") assert header.hasKey("key") assert header.keys() == @["key".cstring] assert header.values() == @["value".cstring] assert header["key"] == "value".cstring header["other"] = "another".cstring assert header["other"] == "another".cstring assert header.entries() == @[("key".cstring, "value".cstring), ("other".cstring, "another".cstring)] assert header.toCstring() == """[["key","value"],["other","another"]]""".cstring header.delete("other") assert header.entries() == @[("key".cstring, "value".cstring)] header.clear() assert header.entries() == @[] assert header.len == 0 block: let header: Headers = newHeaders() header.add("key", "a") header.add("key", "b") ## Duplicated. header.add("key", "c") ## Duplicated. assert header["key"] == "a, b, c".cstring header["key"] = "value".cstring assert header["key"] == "value".cstring block: let header: Headers = newHeaders() header["key"] = "a" header["key"] = "b" ## Overwrites. assert header["key"] == "b".cstring
Procs
func newHeaders(): Headers {.importjs: "new Headers()", ...raises: [], tags: [], forbids: [].}
- https://developer.mozilla.org/en-US/docs/Web/API/Headers Source Edit