NaviServer - programmable web server
4.99  5.0

[ Main Table Of Contents | Table Of Contents | Keyword Index ]

ns_parsefieldvalue(n) 4.99.30 naviserver "NaviServer Built-in Commands"

Name

ns_parsefieldvalue - Parse the content of an HTTP request or reply header field into its components

Table Of Contents

Synopsis

Description

COMMANDS

ns_parsefieldvalue ?-lower? ?-single? ?-strict? ?fieldvalue?

This function parses the provided field value (from an HTTP request or reply header field) into its parts and returns these in the form of a list of Tcl dicts or a single Tcl dict, when -single was specified. The syntax for the contents of these header fields is specified in RFC 7230 section 3.2.6.

Per default, the command assumes a comma separated list of elements, where every element might consist of multiple parts separated by a semicolon. When the -lower is specified, the keys of the returned dicts are converted to lowercase. When the -single is specified, only the first element of the (potentially) comma separated list of elements is returned. When -strict is specified, then the command is expected to parse the full string, otherwise it will just parse as far as possible (when e.g. -single is used.

EXAMPLES

The following examples are from RFC 7239:

 % ns_parsefieldvalue -lower {For="[2001:db8:cafe::17]:4711"}
 {for {[2001:db8:cafe::17]:4711}}
 
 % ns_parsefieldvalue {for=192.0.2.43, for=198.51.100.17}
 {for 192.0.2.43} {for 198.51.100.17}
 
 % ns_parsefieldvalue {for=192.0.2.60;proto=http;by=203.0.113.43}
 {for 192.0.2.60 proto http by 203.0.113.43}

See Also

ns_parseheader, ns_parseurl

Keywords

global built-in, parse