structured_fields

Package VersionHex Docs

Implements parsing and serializing of RFC 9651, with backwards compatibility to RFC 8941.

Usage

gleam add structured_fields
import gleam/io
import gleam/string
import structured_fields/parser
pub fn main() {
let value = "%\"This is intended for display to %c3%bcsers.\""
let parsed = parser.parse_list(value)
case parsed {
Ok(fields) -> {
io.println(string.inspect(fields))
}
Error(e) -> {
io.println("Error parsing structured fields")
io.println(string.inspect(e))
}
}
}

or run:

gleam run -m example

Further documentation can be found at https://hexdocs.pm/structured_fields.

Development

gleam run # Run the project
gleam test # Run the tests

Running the official httpwg test suite

The httpwg/structured-field-tests test cases are not committed to this repo. A generator script converts them into Gleam test files on demand. gleam test will pick them up automatically once generated.

Steps:

  1. Clone the official test repo:

    git clone --depth=1 https://github.com/httpwg/structured-field-tests.git /tmp/structured-field-tests
  2. Install the generator's dependencies (one-time):

    cd scripts && gleam deps download && cd ..
  3. Run the generator:

    cd scripts && gleam run -- /tmp/structured-field-tests && cd ..

    This writes one .gleam file per JSON test file into test/httpwg/ (gitignored).

  4. Run the tests:

    gleam test

The generator also accepts an explicit output directory as a second argument if you need to place the files elsewhere:

cd scripts && gleam run -- /tmp/structured-field-tests ../path/to/output