PageRenderTime 54ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/0.8-beta/uri.html

https://github.com/cpp-netlib/cpp-netlib.github.com
HTML | 284 lines | 259 code | 25 blank | 0 comment | 0 complexity | 4630bd1facacea0b5ba316cabac8a376 MD5 | raw file
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>The URI template &mdash; cpp-netlib v0.8 documentation</title>
  7. <link rel="stylesheet" href="_static/cpp-netlib.css" type="text/css" />
  8. <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  9. <script type="text/javascript">
  10. var DOCUMENTATION_OPTIONS = {
  11. URL_ROOT: '',
  12. VERSION: '0.8',
  13. COLLAPSE_INDEX: false,
  14. FILE_SUFFIX: '.html',
  15. HAS_SOURCE: true
  16. };
  17. </script>
  18. <script type="text/javascript" src="_static/jquery.js"></script>
  19. <script type="text/javascript" src="_static/underscore.js"></script>
  20. <script type="text/javascript" src="_static/doctools.js"></script>
  21. <link rel="top" title="cpp-netlib v0.8 documentation" href="index.html" />
  22. <link rel="up" title="An in-depth look at the cpp-netlib" href="in_depth.html" />
  23. <link rel="next" title="HTTP implementation" href="http.html" />
  24. <link rel="prev" title="The message template" href="message.html" />
  25. </head>
  26. <body>
  27. <div class="document">
  28. <div id="custom-doc" class="yui-t4">
  29. <div id="hd">
  30. <h1><a href="index.html">cpp-netlib v0.8 documentation</a></h1>
  31. <div class="nav">
  32. &laquo; <a href="message.html" title="The message template">previous</a>
  33. |
  34. <a href="in_depth.html" title="An in-depth look at the &lt;tt class=&#34;docutils literal docutils literal docutils literal docutils literal docutils literal&#34;&gt;&lt;span class=&#34;pre&#34;&gt;cpp-netlib&lt;/span&gt;&lt;/tt&gt;" accesskey="U">up</a>
  35. |
  36. <a href="http.html" title="HTTP implementation">next</a> &raquo;</div>
  37. </div>
  38. <div id="bd">
  39. <div id="yui-main">
  40. <div class="yui-b">
  41. <div class="yui-g" id="uri">
  42. <div class="section" id="the-uri-template">
  43. <h1>The URI template<a class="headerlink" href="#the-uri-template" title="Permalink to this headline"></a></h1>
  44. <p>In addition to protocol implementations, the <tt class="xref py py-mod docutils literal"><span class="pre">cpp-netlib</span></tt>
  45. provides a powerful URI template. The URI template implements a
  46. parser based on <a class="reference external" href="http://tools.ietf.org/html/rfc3986">RFC 3986</a>.</p>
  47. <div class="section" id="generic-uri-syntax-overview">
  48. <h2>Generic URI Syntax Overview<a class="headerlink" href="#generic-uri-syntax-overview" title="Permalink to this headline"></a></h2>
  49. <p>A generic URI will take the form:</p>
  50. <div class="highlight-python"><pre>[scheme:]scheme-specific-part[#fragment]</pre>
  51. </div>
  52. <p>A URI is known as <cite>absolute</cite> if it specifies the scheme. Otherwise,
  53. it is known as a relative URI. Currently, <tt class="docutils literal"><span class="pre">basic_uri</span></tt> supports
  54. only absolute URIs.</p>
  55. <p>URIs can be further classified according to whether they&#8217;re
  56. hierarchical or opaque (non-hierarchical).</p>
  57. <p>Some examples of non-hierarchical URIs include:</p>
  58. <div class="highlight-python"><pre>mailto:john.doe@example.com
  59. news:comp.infosystems.www.servers.unix
  60. tel:+1-816-555-1212</pre>
  61. </div>
  62. <p>The data following the first <tt class="docutils literal"><span class="pre">&quot;:&quot;</span></tt> is said to be opaque to the URI
  63. parser and requires no further parsing. By way of example, the
  64. following shows how a non-hierarchical URI is processed by the parser
  65. by defining everything after the <tt class="docutils literal"><span class="pre">&quot;:&quot;</span></tt> to be a part of the path:</p>
  66. <img alt="_images/mailto_uri.png" src="_images/mailto_uri.png" />
  67. <p>A hierarchical URI is identified by a double slash (<tt class="docutils literal"><span class="pre">&quot;//&quot;</span></tt>) after
  68. the scheme and a scheme-specific component, which <a class="reference external" href="http://tools.ietf.org/html/rfc3986">RFC 3986</a> defines
  69. to be:</p>
  70. <div class="highlight-python"><pre>[scheme:][//authority][path][?query][#fragment]</pre>
  71. </div>
  72. <p>The authority component can be further broken down to:</p>
  73. <div class="highlight-python"><pre>[user_info@]host[:port]</pre>
  74. </div>
  75. <p>Examples of hierarchical URIs include:</p>
  76. <div class="highlight-python"><pre>http://www.boost.org/
  77. file:///bin/bash</pre>
  78. </div>
  79. <p>The following example, describing a complex URI using FTP, shows how
  80. a URI is broken down by the parser:</p>
  81. <img alt="_images/ftp_uri.png" src="_images/ftp_uri.png" />
  82. <p>Note that the <tt class="docutils literal"><span class="pre">authority</span></tt> is further subdivided into different
  83. elements. Another example, using HTTP is given below:</p>
  84. <img alt="_images/http_uri.png" src="_images/http_uri.png" />
  85. <p>The difference here between the path in a hierarchical URI and that in
  86. the example above for the non-hierarchical URI.</p>
  87. </div>
  88. <div class="section" id="basic-uri">
  89. <h2><tt class="docutils literal"><span class="pre">basic_uri</span></tt><a class="headerlink" href="#basic-uri" title="Permalink to this headline"></a></h2>
  90. <p>The <tt class="docutils literal"><span class="pre">basic_uri</span></tt> definition is consistent with that of
  91. <tt class="docutils literal"><span class="pre">basic_message</span></tt>:</p>
  92. <div class="highlight-python"><pre>template &lt;class Tag&gt;
  93. class basic_uri;</pre>
  94. </div>
  95. <p>As it stands, the template only supplies a URI parser and no builder.
  96. To use the parser, it&#8217;s as simple as supplying a string to the
  97. constructor:</p>
  98. <div class="highlight-python"><pre>boost::network::uri::uri instance("http://cpp-netlib.github.com/");
  99. assert(boost::is_valid(instance));
  100. std::cout &lt;&lt; "scheme: " &lt;&lt; boost::network::uri::scheme(instance) &lt;&lt; std::endl
  101. &lt;&lt; "host: " &lt;&lt; boost::network::uri::host(instance) &lt;&lt; std::endl;</pre>
  102. </div>
  103. <p>The command-line output of this program will be:</p>
  104. <div class="highlight-python"><pre>scheme: http
  105. host: cpp-netlib.github.com</pre>
  106. </div>
  107. <p>A future version of <tt class="docutils literal"><span class="pre">basic_uri</span></tt> will provide a full builder API.</p>
  108. </div>
  109. <div class="section" id="uri-concept">
  110. <h2><tt class="docutils literal"><span class="pre">URI</span> <span class="pre">Concept</span></tt><a class="headerlink" href="#uri-concept" title="Permalink to this headline"></a></h2>
  111. <p><strong>Legend</strong></p>
  112. <table class="docutils field-list" frame="void" rules="none">
  113. <col class="field-name" />
  114. <col class="field-body" />
  115. <tbody valign="top">
  116. <tr class="field"><th class="field-name">U:</th><td class="field-body">The URI type.</td>
  117. </tr>
  118. <tr class="field"><th class="field-name">u,u_:</th><td class="field-body">An instance of <strong>M</strong>.</td>
  119. </tr>
  120. <tr class="field"><th class="field-name">S:</th><td class="field-body">A string type.</td>
  121. </tr>
  122. <tr class="field"><th class="field-name">s,v:</th><td class="field-body">An instance of <strong>S</strong>.</td>
  123. </tr>
  124. <tr class="field"><th class="field-name">T:</th><td class="field-body">The Tag type.</td>
  125. </tr>
  126. </tbody>
  127. </table>
  128. <table border="1" class="docutils">
  129. <colgroup>
  130. <col width="31%" />
  131. <col width="24%" />
  132. <col width="45%" />
  133. </colgroup>
  134. <thead valign="bottom">
  135. <tr><th class="head">Construct</th>
  136. <th class="head">Result</th>
  137. <th class="head">Description</th>
  138. </tr>
  139. </thead>
  140. <tbody valign="top">
  141. <tr><td><tt class="docutils literal"><span class="pre">U(u)</span></tt></td>
  142. <td>Instance of U</td>
  143. <td>Copy constructible.</td>
  144. </tr>
  145. <tr><td><tt class="docutils literal"><span class="pre">U(s)</span></tt></td>
  146. <td>Instance of U</td>
  147. <td>Constructible from string.</td>
  148. </tr>
  149. <tr><td><tt class="docutils literal"><span class="pre">u</span> <span class="pre">=</span> <span class="pre">u_;</span></tt></td>
  150. <td>Reference to u</td>
  151. <td>Assignable.</td>
  152. </tr>
  153. <tr><td><tt class="docutils literal"><span class="pre">u</span> <span class="pre">=</span> <span class="pre">s;</span></tt></td>
  154. <td>Reference to u</td>
  155. <td>Assignable from string.</td>
  156. </tr>
  157. <tr><td><tt class="docutils literal"><span class="pre">swap(u,</span> <span class="pre">u_);</span></tt></td>
  158. <td><tt class="docutils literal"><span class="pre">void</span></tt></td>
  159. <td>Swappable.</td>
  160. </tr>
  161. <tr><td><tt class="docutils literal"><span class="pre">scheme(u);</span></tt></td>
  162. <td>Convertible to S</td>
  163. <td>Retrieve the URI scheme of <tt class="docutils literal"><span class="pre">u</span></tt>.</td>
  164. </tr>
  165. <tr><td><tt class="docutils literal"><span class="pre">user_info(u);</span></tt></td>
  166. <td>Convertible to S</td>
  167. <td>Retrieve the user info of <tt class="docutils literal"><span class="pre">u</span></tt>.</td>
  168. </tr>
  169. <tr><td><tt class="docutils literal"><span class="pre">host(u);</span></tt></td>
  170. <td>Convertible to S</td>
  171. <td>Retrieve the host of <tt class="docutils literal"><span class="pre">u</span></tt>.</td>
  172. </tr>
  173. <tr><td><tt class="docutils literal"><span class="pre">port(u);</span></tt></td>
  174. <td>Convertible to H</td>
  175. <td>Retrieve the port of <tt class="docutils literal"><span class="pre">u</span></tt>.</td>
  176. </tr>
  177. <tr><td><tt class="docutils literal"><span class="pre">path(u);</span></tt></td>
  178. <td>Convertible to S</td>
  179. <td>Retrieve the path of <tt class="docutils literal"><span class="pre">u</span></tt>.</td>
  180. </tr>
  181. <tr><td><tt class="docutils literal"><span class="pre">query(u);</span></tt></td>
  182. <td>Convertible to S</td>
  183. <td>Retrieve the query string of <tt class="docutils literal"><span class="pre">u</span></tt>.</td>
  184. </tr>
  185. <tr><td><tt class="docutils literal"><span class="pre">fragment(u);</span></tt></td>
  186. <td>Convertible to S</td>
  187. <td>Retrieve the fragment of <tt class="docutils literal"><span class="pre">u</span></tt>.</td>
  188. </tr>
  189. </tbody>
  190. </table>
  191. </div>
  192. </div>
  193. </div>
  194. </div>
  195. </div>
  196. <div class="yui-b" id="sidebar">
  197. <div class="sphinxsidebar">
  198. <div class="sphinxsidebarwrapper">
  199. <h3><a href="index.html">Table Of Contents</a></h3>
  200. <ul>
  201. <li><a class="reference internal" href="#">The URI template</a><ul>
  202. <li><a class="reference internal" href="#generic-uri-syntax-overview">Generic URI Syntax Overview</a></li>
  203. <li><a class="reference internal" href="#basic-uri"><tt class="docutils literal"><span class="pre">basic_uri</span></tt></a></li>
  204. <li><a class="reference internal" href="#uri-concept"><tt class="docutils literal"><span class="pre">URI</span> <span class="pre">Concept</span></tt></a></li>
  205. </ul>
  206. </li>
  207. </ul>
  208. <h3>Browse</h3>
  209. <ul>
  210. <li>Prev: <a href="message.html">The message template</a></li>
  211. <li>Next: <a href="http.html">HTTP implementation</a></li>
  212. </ul>
  213. <h3>You are here:</h3>
  214. <ul>
  215. <li>
  216. <a href="index.html">cpp-netlib v0.8 documentation</a>
  217. <ul><li><a href="in_depth.html">An in-depth look at the <tt class="docutils literal docutils literal docutils literal docutils literal docutils literal"><span class="pre">cpp-netlib</span></tt></a>
  218. <ul><li>The URI template</li></ul>
  219. </li></ul>
  220. </li>
  221. </ul>
  222. <h3>This Page</h3>
  223. <ul class="this-page-menu">
  224. <li><a href="_sources/uri.txt"
  225. rel="nofollow">Show Source</a></li>
  226. </ul>
  227. <div id="searchbox" style="display: none">
  228. <h3>Quick search</h3>
  229. <form class="search" action="search.html" method="get">
  230. <input type="text" name="q" size="18" />
  231. <input type="submit" value="Go" />
  232. <input type="hidden" name="check_keywords" value="yes" />
  233. <input type="hidden" name="area" value="default" />
  234. </form>
  235. <p class="searchtip" style="font-size: 90%">
  236. Enter search terms or a module, class or function name.
  237. </p>
  238. </div>
  239. <script type="text/javascript">$('#searchbox').show(0);</script>
  240. </div>
  241. </div>
  242. </div>
  243. </div>
  244. <div id="ft">
  245. <div class="nav">
  246. &laquo; <a href="message.html" title="The message template">previous</a>
  247. |
  248. <a href="in_depth.html" title="An in-depth look at the &lt;tt class=&#34;docutils literal docutils literal docutils literal docutils literal docutils literal&#34;&gt;&lt;span class=&#34;pre&#34;&gt;cpp-netlib&lt;/span&gt;&lt;/tt&gt;" accesskey="U">up</a>
  249. |
  250. <a href="http.html" title="HTTP implementation">next</a> &raquo;</div>
  251. </div>
  252. </div>
  253. <div class="clearer"></div>
  254. </div>
  255. <div class="footer">
  256. documentation automatically generated by <a href="http://sphinx.pocoo.org">Sphinx</a> | style mostly stolen from <a href="http://lettuce.it">lettuce.it</a>
  257. </div>
  258. </body>
  259. </html>