refreq.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>ne_request_create</title><link rel="stylesheet" type="text/css" href="manual.css"><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot"><link rel="home" href="index.html" title="neon HTTP/WebDAV client library"><link rel="up" href="ref.html" title="neon API reference"><link rel="prev" href="refsessflags.html" title="ne_set_session_flag"><link rel="next" href="refreqhdr.html" title="ne_add_request_header"></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">ne_request_create</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="refsessflags.html">Prev</a> </td><th width="60%" align="center">neon API reference</th><td width="20%" align="right"> <a accesskey="n" href="refreqhdr.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="refreq"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>ne_request_create, ne_request_dispatch, ne_request_destroy — low-level HTTP request handling</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><pre class="funcsynopsisinfo">#include &lt;ne_request.h&gt;</pre><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="funcprototype"><code><code xmlns="" class="funcdef">ne_request *<b class="fsfunc">ne_request_create</b>(</code>ne_session *<var xmlns="" class="pdparam">session</var>, const char *<var xmlns="" class="pdparam">method</var>, const char *<var xmlns="" class="pdparam">target</var><code xmlns="">)</code>;</code></div><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="funcprototype"><code><code xmlns="" class="funcdef">int <b class="fsfunc">ne_request_dispatch</b>(</code>ne_request *<var xmlns="" class="pdparam">req</var><code xmlns="">)</code>;</code></div><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="funcprototype"><code><code xmlns="" class="funcdef">void <b class="fsfunc">ne_request_destroy</b>(</code>ne_request *<var xmlns="" class="pdparam">req</var><code xmlns="">)</code>;</code></div></div></div><div class="refsect1"><a name="id3173"></a><h2>Description</h2><p>The <em class="type">ne_request</em> object represents an HTTP
  2. request and the associated response. The
  3. <code class="function">ne_request_create</code> function creates a new
  4. request object for the given <code class="parameter">session</code>.
  5. The target resource for the request is identified by the
  6. <code class="parameter">target</code>, parameter, and the method to be
  7. performed on that resource via the
  8. <code class="parameter">method</code> parameter.</p><p>The <code class="parameter">target</code> string used must conform to
  9. the <code class="literal">request-target</code> definition given in <a class="ulink" href="https://www.rfc-editor.org/rfc/rfc9112" target="_top">RFC 9112</a>. Usually
  10. this will take the <code class="literal">abolute-path</code> form, which
  11. optionally includes a query string.</p><p>To <span class="emphasis"><em>dispatch</em></span> a request, and process the response, the
  12. <code class="function">ne_request_dispatch</code> function can be used. An
  13. alternative is to use the (more complex, but more flexible)
  14. combination of the <code class="function">ne_begin_request</code>,
  15. <code class="function">ne_end_request</code>, and
  16. <code class="function">ne_read_response_block</code> functions; see
  17. <code class="function">ne_begin_request</code>. <span class="emphasis"><em>Dispatching</em></span> a request may require
  18. multiple iterations of a request being sent and response received, for example
  19. if authentication is used (see <a class="xref" href="refauth.html#ne_set_server_auth">ne_set_server_auth</a>), or if a persistent
  20. connection times out; this is handled internally by <code class="function">ne_request_dispatch</code>.</p><p>To add extra headers in the request, the functions <a class="xref" href="refreqhdr.html#ne_add_request_header">ne_add_request_header</a> and <a class="xref" href="refreqhdr.html#ne_print_request_header">ne_print_request_header</a> can be used. To include a message
  21. body with the request, one of the functions
  22. <code class="function">ne_set_request_body_buffer</code>, <code class="function">ne_set_request_body_fd</code>, or
  23. <code class="function">ne_set_request_body_provider</code> can be used.</p><p>The return value of
  24. <code class="function">ne_request_dispatch</code> indicates merely whether the
  25. request was sent and the response read successfully. To discover the
  26. result of the operation, <a class="xref" href="refgetst.html#ne_get_status">ne_get_status</a>, along with
  27. any processing of the response headers and message body.</p><p>A request can only be dispatched once: calling
  28. <code class="function">ne_request_dispatch</code> more than once on a
  29. single <em class="type">ne_request</em> object produces undefined
  30. behaviour. Once all processing associated with the request
  31. object is complete, use the
  32. <code class="function">ne_request_destroy</code> function to destroy
  33. the resources associated with it. Any subsequent use of the
  34. request object produces undefined behaviour.</p><p>Request methods are assumed to be <a class="ulink" href="https://www.rfc-editor.org/rfc/rfc9110.html#name-idempotent-methods" target="_top">idempotent</a>
  35. by default. For a request using a non-idempotent method such
  36. as <code class="literal">POST</code>, the
  37. <code class="literal">NE_REQFLAG_IDEMPOTENT</code> flag must be
  38. disabled using <a class="xref" href="refreqflags.html#ne_set_request_flag">ne_set_request_flag</a>.</p></div><div class="refsect1"><a name="id3214"></a><h2>Return value</h2><p>The <code class="function">ne_request_create</code> function
  39. returns a pointer to a request object (and never <code class="literal">NULL</code>).</p><p>The <code class="function">ne_request_dispatch</code> function
  40. returns zero if the request was dispatched successfully, and a
  41. non-zero error code code otherwise, as described in the
  42. following section.</p></div><div class="refsect1"><a name="error-codes"></a><h2>Error codes</h2><p>Error codes have a non-zero value, and correspond to an
  43. <code class="literal">NE_*</code> macro definition, as listed below.
  44. Future versions of neon may introduce additional error code
  45. definitions. Functions which return an error code and have an
  46. associated session object set the session error string (see
  47. <a class="xref" href="referr.html#ne_get_error">ne_get_error</a>) unless documented
  48. otherwise.</p><div class="variablelist"><table border="0" class="variablelist"><colgroup><col align="left" valign="top"><col></colgroup><tbody><tr><td><p><span class="term"><span class="errorcode">NE_ERROR</span></span></p></td><td>Request failed (see session error string)</td></tr><tr><td><p><span class="term"><span class="errorcode">NE_LOOKUP</span></span></p></td><td>The DNS lookup for the server (or proxy server) failed.</td></tr><tr><td><p><span class="term"><span class="errorcode">NE_AUTH</span></span></p></td><td>Authentication failed on the server.</td></tr><tr><td><p><span class="term"><span class="errorcode">NE_PROXYAUTH</span></span></p></td><td>Authentication failed on the proxy server.</td></tr><tr><td><p><span class="term"><span class="errorcode">NE_CONNECT</span></span></p></td><td>A connection to the server could not be established.</td></tr><tr><td><p><span class="term"><span class="errorcode">NE_TIMEOUT</span></span></p></td><td>A timeout occurred while waiting for the server to respond.</td></tr><tr><td><p><span class="term"><span class="errorcode">NE_REDIRECT</span></span></p></td><td>A valid redirect was retuerned. <span class="emphasis"><em>Note:</em></span> Only returned if redirect handling is registered for the session using <a class="xref" href="refred.html#ne_redirect_register">ne_redirect_register</a>.</td></tr></tbody></table></div></div><div class="refsect1"><a name="id3264"></a><h2>Notes</h2><p>The <code class="parameter">path</code>,
  49. <code class="parameter">method</code> and
  50. <code class="parameter">target</code> parameters of
  51. <code class="function">ne_request_create</code> are used directly in
  52. request data without validation, so must not be taken from
  53. untrusted sources. For example, allowing insertion of
  54. unescaped CR, LF or other control characters in these
  55. parameters may result in unexpected or insecure behaviour.</p><p>neon does not impose any length restrictions on
  56. request input data.</p></div><div class="refsect1"><a name="id3272"></a><h2>Example</h2><p>An example of applying a <code class="literal">MKCOL</code>
  57. operation to the resource at the location
  58. <code class="literal">http://www.example.com/foo/bar/</code>:</p><pre class="programlisting">ne_session *sess = ne_session_create("http", "www.example.com", 80);
  59. ne_request *req = ne_request_create(sess, "MKCOL", "/foo/bar/");
  60. if (ne_request_dispatch(req)) {
  61. printf("Request failed: %s\n", ne_get_error(sess));
  62. }
  63. ne_request_destroy(req);</pre></div><div class="refsect1"><a name="id3278"></a><h2>See also</h2><p><a class="xref" href="referr.html#ne_get_error">ne_get_error</a>, <a class="xref" href="referr.html#ne_set_error">ne_set_error</a>, <a class="xref" href="refgetst.html#ne_get_status">ne_get_status</a>, <a class="xref" href="refreqhdr.html#ne_add_request_header">ne_add_request_header</a>, <a class="xref" href="refreqbody.html#ne_set_request_body_buffer">ne_set_request_body_buffer</a>, <a class="xref" href="refreqflags.html#ne_set_request_flag">ne_set_request_flag</a>, <a class="xref" href="refred.html#ne_redirect_register">ne_redirect_register</a>.</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="refsessflags.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ref.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="refreqhdr.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">ne_set_session_flag </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> ne_add_request_header</td></tr></table></div></body></html>