| <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>http_accept</title><link rel="stylesheet" type="text/css" href="rivet.css"><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"><link rel="home" href="index.html" title="Apache Rivet"><link rel="up" href="commands.html" title="Rivet Tcl Commands and Variables"><link rel="prev" href="html.html" title="html"><link rel="next" href="import_keyvalue_pairs.html" title="import_keyvalue_pairs"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">http_accept</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="html.html"><img src="images/prev.png" alt="Prev"></a> </td><th width="60%" align="center">Rivet Tcl Commands and Variables</th><td width="20%" align="right"> <a accesskey="n" href="import_keyvalue_pairs.html"><img src="images/next.png" alt="Next"></a></td></tr></table></div><div class="refentry"><div class="refentry.separator"><hr></div><a name="http_accept"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>http_accept — Parse HTTP Accept header lines</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="cmdsynopsis" style="width:80%"><div style="border: 1px solid #282; margin:1ex ; padding:.4ex; padding-left: 0.8ex; word-spacing:1ex "><span style="font-weight:bold ; font-family:monospace">::rivet::http_accept |
| ?<span style="font-family:monospace; font-weight: bold;"><em class="replaceable"><code>-zeroweight</code></em></span>? |
| ?<span style="font-family:monospace; font-weight: bold;"><em class="replaceable"><code>-default</code></em></span>? |
| ?<span style="font-family:monospace; font-weight: bold;"><em class="replaceable"><code>-list</code></em></span>? |
| http_accept_line</span> </div></div></div><div class="refsect1"><a name="idm1038"></a><h2>Description</h2><p style="width:90%"> |
| 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 |
| </p><p style="width:90%"> |
| <span style="font-family:monospace"><span class="command"><strong>::rivet::http_accept</strong></span></span> returns a dictionary |
| value in which every content preference is matched to its |
| precedence value |
| </p><pre class="programlisting">load_headers |
| set language_precedence [::rivet::http_accept $headers(Accept-Language)] |
| foreach lan [dict keys $language_precedence] { |
| puts "$lan -> [dict get $language_precedence $lan]" |
| }</pre><p style="width:90%"> |
| when run from a browser where 5 languages were chosen |
| would output |
| </p><pre class="programlisting">en-us -> 1 |
| en -> 0.8 |
| it -> 0.6 |
| de-de -> 0.4 |
| fr-fr -> 0.2</pre><p style="width:90%"> |
| The <em class="replaceable"><code>-list</code></em> switch would suppress |
| the precedence values and the accepted fields |
| are returned listed with decreasing precedence order. |
| </p><pre class="programlisting"> puts [::rivet::http_accept -list $headers(Accept-Language)] |
| text/html application/xhtml+xml application/xml */* |
| </pre><p style="width:90%"> |
| |
| </p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="html.html"><img src="images/prev.png" alt="Prev"></a> </td><td width="20%" align="center"><a accesskey="u" href="commands.html"><img src="images/up.png" alt="Up"></a></td><td width="40%" align="right"> <a accesskey="n" href="import_keyvalue_pairs.html"><img src="images/next.png" alt="Next"></a></td></tr><tr><td width="40%" align="left" valign="top">html </td><td width="20%" align="center"><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a></td><td width="40%" align="right" valign="top"> import_keyvalue_pairs</td></tr></table></div></body></html> |