http_sfv 0.1.0 http_sfv: ^0.1.0 copied to clipboard
Dart implementation of Structured Field Values for HTTP (RFC8941)
http_sfv (Structured Field Values) #
A Dart implementation of the Structured Field Values for HTTP (RFC 8941) specification.
Usage #
Use StructuredFieldValue.decode
to parse a header string into a structured field value.
import 'package:http_sfv/http_sfv.dart';
void main() {
const header = '"foo";bar;baz=tok, (foo bar);bat';
final decoded = StructuredFieldValue.decode(
header,
type: StructuredFieldValueType.list,
);
print(decoded);
// Prints: List(Item(foo, bar: true, baz: tok), InnerList([Item(foo), Item(bar)], bat: true))
}
Use StructuredFieldValue.encode
to convert a structured field value to a header string.
import 'package:http_sfv/http_sfv.dart';
void main() {
final dictionary = StructuredFieldDictionary({
'a': false,
'b': true,
'c': StructuredFieldItem(
true,
parameters: {
'foo': 'bar',
},
),
});
print(dictionary.encode());
// Prints: "a=?0, b, c;foo=bar"
}