# NAME HTTP::libsfparse - parse RFC 9651 HTTP Structured Fields using libsfparse # SYNOPSIS use HTTP::libsfparse qw( parse_item parse_list parse_dictionary :types :index ); # Every item is [ $type, $value, $params ], and the positions have # names, so none of this is counted out by hand. # Single item my $item = parse_item('text/html;q=0.8'); $item->[SFP_TYPE] == SFPARSE_TYPE_TOKEN; # true $item->[SFP_VALUE]; # 'text/html' $item->[SFP_PARAMS][0][SFP_KEY]; # 'q' $item->[SFP_PARAMS][0][SFP_ITEM][SFP_VALUE]; # 0.8 # Dictionary: RFC 9218 priority. A dictionary is a list of pairs. my $pri = parse_dictionary('u=5, i'); $pri->[0][SFP_KEY]; # 'u' $pri->[0][SFP_ITEM][SFP_VALUE]; # 5 $pri->[1][SFP_ITEM][SFP_TYPE] == SFPARSE_TYPE_BOOLEAN; # true # Pairs are easy to index when you do not mind losing duplicate keys my %pri = map { $_->[SFP_KEY] => $_->[SFP_ITEM] } @$pri; $pri{u}[SFP_VALUE]; # 5 # List, with an inner list and parameters my $list = parse_list('(1 2 3;b="foo"), bar, baz;f=:aGVsbG8=:'); my $inner = $list->[0][SFP_VALUE]; $list->[0][SFP_TYPE] == SFPARSE_TYPE_INNER_LIST; # true $inner->[1][SFP_VALUE]; # 2 $inner->[2][SFP_PARAMS][0][SFP_ITEM][SFP_VALUE]; # 'foo' $list->[2][SFP_PARAMS][0][SFP_ITEM][SFP_VALUE]; # 'hello' # Malformed input throws my $ok = eval { parse_list('a, b, "unterminated'); 1 }; # DESCRIPTION This module is an XS binding to [libsfparse](https://github.com/ngtcp2/sfparse), the C parser for HTTP Structured Field Values ([RFC 9651](https://www.rfc-editor.org/rfc/rfc9651), which obsoletes RFC 8941) written for the ngtcp2 and nghttp3 QUIC/HTTP3 stacks. It uses a bundled copy of libsfparse, and not a version that may already be installed on your system. You may prefer to use [HTTP::StructuredField](https://metacpan.org/pod/HTTP%3A%3AStructuredField) instead. # REQUIREMENTS This module lists the following modules as runtime dependencies: - [Exporter](https://metacpan.org/pod/Exporter) version 5.57 or later - [Hash::Ordered](https://metacpan.org/pod/Hash%3A%3AOrdered) version 0.009 or later - [Math::Int64](https://metacpan.org/pod/Math%3A%3AInt64) - [Ref::Util](https://metacpan.org/pod/Ref%3A%3AUtil) - [Sub::Util](https://metacpan.org/pod/Sub%3A%3AUtil) - [XSLoader](https://metacpan.org/pod/XSLoader) - [experimental](https://metacpan.org/pod/experimental) - [perl](https://metacpan.org/pod/perl) version v5.20.0 or later - [strict](https://metacpan.org/pod/strict) - [warnings](https://metacpan.org/pod/warnings) See the `META.json` file for the full list of prerequisites. # INSTALLATION The latest version of this module (along with any dependencies) can be installed from [CPAN](https://www.cpan.org) with the `cpan` tool that is included with Perl: ``` cpan HTTP::StructuredField ``` You can also extract the distribution archive and install this module (along with any dependencies): ``` cpan . ``` You can also install this module manually using the following commands: ``` perl Makefile.PL make make test make install ``` For more information, see [How to install CPAN modules](https://www.cpan.org/modules/INSTALL.html). # KNOWN ISSUES RFC 9651 specifies that integers can be up to 15 digits long, which makes decoding them into integers problematic for 32-bit systems. Numbers that are too large will be represented using [Math::Int64](https://metacpan.org/pod/Math%3A%3AInt64). libsfparse also provides `sfparse_unescape`, `sfparse_base64decode` and `sfparse_pctdecode`. Those functions assume their input has already been validated by the parser and that the output buffer is large enough; handed arbitrary Perl strings they would read and write out of bounds. They are used internally on parser-produced values only, and are not exported. # SEE ALSO [HTTP::StructuredField](https://metacpan.org/pod/HTTP%3A%3AStructuredField) provides an object-oriented interface. [RFC 9651](https://www.rfc-editor.org/rfc/rfc9651), Structured Field Values for HTTP. [RFC 9218](https://www.rfc-editor.org/rfc/rfc9218), Extensible Prioritization Scheme for HTTP, whose `Priority` field is a dictionary. [libsfparse](https://github.com/ngtcp2/sfparse) and its [documentation](https://nghttp2.org/sfparse/). # SUPPORT Please report any bugs or feature requests on the bugtracker website [https://github.com/robrwo/perl-HTTP-StructuredField/issues](https://github.com/robrwo/perl-HTTP-StructuredField/issues) When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. # SOURCE The development version is on github at [https://github.com/robrwo/perl-HTTP-StructuredField](https://github.com/robrwo/perl-HTTP-StructuredField) and may be cloned from [https://github.com/robrwo/perl-HTTP-StructuredField.git](https://github.com/robrwo/perl-HTTP-StructuredField.git) # AUTHOR Robert Rothenberg The XS wrapper [HTTP::libsfparse](https://metacpan.org/pod/HTTP%3A%3Alibsfparse) was written with the assistance of Claude Opus. # CONTRIBUTOR Paul Johnson # COPYRIGHT AND LICENSE This software is Copyright (c) 2026 by Robert Rothenberg. This is free software, licensed under: ``` The MIT (X11) License ``` The bundled copy of libsfparse is Copyright (c) 2023 Tatsuhiro Tsujikawa and other sfparse contributors. It is distributed under the MIT license; see `src/LICENSE.sfparse`. It is included unmodified. This includes code from [Math::Int64](https://metacpan.org/pod/Math%3A%3AInt64), Copyright (c) 2007-2024 by Salvador FandiƱo and Dave Rolsky. It is distributed under the the same terms as the Perl 5 programming language system itself; see `LICENSE.Math-Int64`.