http_accept — Parse HTTP Accept header lines
-zeroweight?
?-default?
?-list?
http_accept_line Command for parsing HTTP Accept header lines that tell the server about preferences and/or capabilities of the browser (e.g. content language,media type, etc.). The following script
::rivet::http_accept returns a dictionary value in which every content preference is matched to its precedence value
::rivet::load_headers
set language_precedence [::rivet::http_accept $headers(Accept-Language)]
foreach lan [dict keys $language_precedence] {
puts "$lan -> [dict get $language_precedence $lan]"
}when run from a browser where 5 languages were chosen would output
en-us -> 1 en -> 0.8 it -> 0.6 de-de -> 0.4 fr-fr -> 0.2
The -list switch would suppress
the precedence values and the accepted fields
are returned listed with decreasing precedence order.
puts [::rivet::http_accept -list $headers(Accept)]
text/html application/xhtml+xml application/xml */*