Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-httpclient

Named HTTP clients for Pudu: a client factory, delegating handlers, pooled keep-alive connections, handler lifetimes, logging, and resilience

0.1.1Apache-2.01

InstallClose

HeadersTest.pudu

Pudu33 lines2.7 KB

GitHub ↗
1/** @Test.Domain.Headers.Suite — header lists compared without regard to case */2module PuduLangHttpClient.Domain.HeadersTest34import Std.Io as Io5import Std.Test as Test6import PuduLangHttpClient.Domain.Headers as Headers78/// Runs the suite.9fn main() -> Int {10  let headers = [("Accept", "text/plain"), ("X-Id", "1"), ("accept", "text/html")]11  let checks = Test.suite("Domain.Headers", &[12      Test.equals("the first value is found without regard to case", &(Headers.get(&headers, "ACCEPT"), Headers.get(&headers, "x-id"), Headers.get(&headers, "missing")), &(Some("text/plain"), Some("1"), None)),13      Test.equals("every value is found in order", &Headers.values(&headers, "accept"), &["text/plain", "text/html"]),14      Test.that("presence ignores case", Headers.has(&headers, "x-ID") && !Headers.has(&headers, "x-other")),15      Test.equals("adding keeps earlier values", &Headers.add(&[("a", "1")], "A", "2"), &[("a", "1"), ("A", "2")]),16      Test.equals("setting replaces every value", &Headers.set(&headers, "accept", "*/*"), &[("X-Id", "1"), ("accept", "*/*")]),17      Test.equals("removing drops every value", &Headers.remove(&headers, "Accept"), &[("X-Id", "1")]),18      Test.equals("removing a set of names drops each", &Headers.removeAll(&headers, &#{"accept", "x-id"}), &[]),19      Test.equals("defaults fill only the names a message lacks, before its own", &Headers.merged(&[("user-agent", "pudu"), ("Accept", "*/*")], &[("accept", "text/plain")]), &[("user-agent", "pudu"), ("accept", "text/plain")]),20      Test.equals("redacted values are hidden and names kept", &Headers.redacted(&[("Authorization", "Bearer x"), ("accept", "a")], |name: Str| name == "authorization"), &[("Authorization", Headers.REDACTED), ("accept", "a")]),21      Test.that("content headers are recognised without regard to case", Headers.isContentHeader("Content-Type") && Headers.isContentHeader("expires") && !Headers.isContentHeader("accept")),22      Test.equals("headers split into the message's and the body's", &Headers.splitContent(&[("date", "d"), ("Content-Length", "3")]), &([("date", "d")], [("Content-Length", "3")])),23      Test.equals("a header with a line break, a colon in its name, or no name is unwritable", &[Headers.unwritable(&[("a", "b\r\nc: d")]), Headers.unwritable(&[("a:b", "c")]), Headers.unwritable(&[("", "c")]), Headers.unwritable(&[("ok", "fine")])], &[Some("a"), Some("a:b"), Some(""), None]),24      Test.that("a listed token is found in a comma-separated value", Headers.lists("keep-alive, Close", "close") && Headers.lists("gzip", "GZIP")),25      Test.not("a token is not found inside another", Headers.lists("closed, x", "close"))26    ])27  let ran = Test.run(&checks)28  for failure in Test.failuresOf(&ran) {29    let _reported = Io.writeErrorLine(failure)30  }31  Test.report(&ran)32}33