req.xml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <refentry id="refreq">
  2. <refmeta>
  3. <refentrytitle>ne_request_create</refentrytitle>
  4. <manvolnum>3</manvolnum>
  5. </refmeta>
  6. <refnamediv>
  7. <refname id="ne_request_create">ne_request_create</refname>
  8. <refname id="ne_request_dispatch">ne_request_dispatch</refname>
  9. <refname id="ne_request_destroy">ne_request_destroy</refname>
  10. <refpurpose>low-level HTTP request handling</refpurpose>
  11. </refnamediv>
  12. <refsynopsisdiv>
  13. <funcsynopsis>
  14. <funcsynopsisinfo>#include &lt;ne_request.h&gt;</funcsynopsisinfo>
  15. <funcprototype>
  16. <funcdef>ne_request *<function>ne_request_create</function></funcdef>
  17. <paramdef>ne_session *<parameter>session</parameter></paramdef>
  18. <paramdef>const char *<parameter>method</parameter></paramdef>
  19. <paramdef>const char *<parameter>path</parameter></paramdef>
  20. </funcprototype>
  21. <funcprototype>
  22. <funcdef>int <function>ne_request_dispatch</function></funcdef>
  23. <paramdef>ne_request *<parameter>req</parameter></paramdef>
  24. </funcprototype>
  25. <funcprototype>
  26. <funcdef>void <function>ne_request_destroy</function></funcdef>
  27. <paramdef>ne_request *<parameter>req</parameter></paramdef>
  28. </funcprototype>
  29. </funcsynopsis>
  30. </refsynopsisdiv>
  31. <refsect1>
  32. <title>Description</title>
  33. <para>The <type>ne_request</type> object represents an HTTP
  34. request and the associated response.
  35. The <function>ne_request_create</function> function creates a
  36. new request object for the
  37. given <parameter>session</parameter>. The target resource for
  38. the request is identified by the <parameter>path</parameter>,
  39. and the method to be performed on that resource via
  40. the <parameter>method</parameter> parameter.</para>
  41. <para>The <parameter>path</parameter> string used must conform to the
  42. <literal>abs_path</literal> definition given in RFC2396, with an
  43. optional "?query" part, and must be URI-escaped by the caller (for
  44. instance, using <function>ne_path_escape</function>). If the string
  45. comes from an untrusted source, failure to perform URI-escaping
  46. results in a security vulnerability.</para>
  47. <para>To dispatch a request, and process the response, the
  48. <function>ne_request_dispatch</function> function can be used. An
  49. alternative is to use the (more complex, but more flexible)
  50. combination of the <function>ne_begin_request</function>,
  51. <function>ne_end_request</function>, and
  52. <function>ne_read_response_block</function> functions; see
  53. <function>ne_begin_request</function>.</para>
  54. <para>To add extra headers in the request, the functions <xref
  55. linkend="ne_add_request_header"/> and <xref
  56. linkend="ne_print_request_header"/> can be used. To include a message
  57. body with the request, one of the functions
  58. <function>ne_set_request_body_buffer</function>, <xref
  59. linkend="ne_set_request_body_fd"/>, or
  60. <function>ne_set_request_body_provider</function> can be used.</para>
  61. <para>The return value of
  62. <function>ne_request_dispatch</function> indicates merely whether the
  63. request was sent and the response read successfully. To discover the
  64. result of the operation, <xref linkend="ne_get_status"/>, along with
  65. any processing of the response headers and message body.</para>
  66. <para>A request can only be dispatched once: calling
  67. <function>ne_request_dispatch</function> more than once on a
  68. single <type>ne_request</type> object produces undefined
  69. behaviour. Once all processing associated with the request
  70. object is complete, use the
  71. <function>ne_request_destroy</function> function to destroy
  72. the resources associated with it. Any subsequent use of the
  73. request object produces undefined behaviour.</para>
  74. <para>If a request is being using a non-idempotent method such
  75. as <literal>POST</literal>, the
  76. <literal>NE_REQFLAG_IDEMPOTENT</literal> flag should be
  77. disabled; see <xref linkend="ne_set_request_flag"/>.</para>
  78. </refsect1>
  79. <refsect1>
  80. <title>Return value</title>
  81. <para>The <function>ne_request_create</function> function
  82. returns a pointer to a request object (and never &null;).</para>
  83. <para>The <function>ne_request_dispatch</function> function
  84. returns zero if the request was dispatched successfully, and a
  85. non-zero error code otherwise.</para>
  86. </refsect1>
  87. <!-- TODO: abs_path description in a NOTES section -->
  88. <refsect1>
  89. <title>Errors</title>
  90. <variablelist>
  91. <varlistentry><term><errorcode>NE_ERROR</errorcode></term>
  92. <listitem>
  93. <simpara>Request failed (see session error string)</simpara>
  94. </listitem>
  95. </varlistentry>
  96. <varlistentry><term><errorcode>NE_LOOKUP</errorcode></term>
  97. <listitem>
  98. <simpara>The DNS lookup for the server (or proxy server) failed.</simpara>
  99. </listitem>
  100. </varlistentry>
  101. <varlistentry><term><errorcode>NE_AUTH</errorcode></term>
  102. <listitem>
  103. <simpara>Authentication failed on the server.</simpara>
  104. </listitem>
  105. </varlistentry>
  106. <varlistentry><term><errorcode>NE_PROXYAUTH</errorcode></term>
  107. <listitem>
  108. <simpara>Authentication failed on the proxy server.</simpara>
  109. </listitem>
  110. </varlistentry>
  111. <varlistentry><term><errorcode>NE_CONNECT</errorcode></term>
  112. <listitem>
  113. <simpara>A connection to the server could not be established.</simpara>
  114. </listitem>
  115. </varlistentry>
  116. <varlistentry><term><errorcode>NE_TIMEOUT</errorcode></term>
  117. <listitem>
  118. <simpara>A timeout occurred while waiting for the server to respond.</simpara>
  119. </listitem>
  120. </varlistentry>
  121. </variablelist>
  122. </refsect1>
  123. <refsect1>
  124. <title>Example</title>
  125. <para>An example of applying a <literal>MKCOL</literal>
  126. operation to the resource at the location
  127. <literal>http://www.example.com/foo/bar/</literal>:</para>
  128. <programlisting>ne_session *sess = ne_session_create("http", "www.example.com", 80);
  129. ne_request *req = ne_request_create(sess, "MKCOL", "/foo/bar/");
  130. if (ne_request_dispatch(req)) {
  131. printf("Request failed: %s\n", ne_get_error(sess));
  132. }
  133. ne_request_destroy(req);</programlisting>
  134. </refsect1>
  135. <refsect1>
  136. <title>See also</title>
  137. <para><xref linkend="ne_get_error"/>, <xref
  138. linkend="ne_set_error"/>, <xref linkend="ne_get_status"/>, <xref
  139. linkend="ne_add_request_header"/>, <xref
  140. linkend="ne_set_request_body_buffer"/>, <xref linkend="ne_set_request_flag"/>.</para>
  141. </refsect1>
  142. </refentry>