reqbody.xml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <refentry id="refreqbody">
  2. <refmeta>
  3. <refentrytitle>ne_set_request_body_buffer</refentrytitle>
  4. <manvolnum>3</manvolnum>
  5. </refmeta>
  6. <refnamediv>
  7. <refname id="ne_set_request_body_buffer">ne_set_request_body_buffer</refname>
  8. <refname id="ne_set_request_body_fd">ne_set_request_body_fd</refname>
  9. <refname id="ne_set_request_body_provider">ne_set_request_body_provider</refname>
  10. <refpurpose>include a message body with a request</refpurpose>
  11. </refnamediv>
  12. <refsynopsisdiv>
  13. <funcsynopsis>
  14. <funcsynopsisinfo>#include &lt;ne_request.h&gt;</funcsynopsisinfo>
  15. <funcprototype>
  16. <funcdef>void <function>ne_set_request_body_buffer</function></funcdef>
  17. <paramdef>ne_request *<parameter>req</parameter></paramdef>
  18. <paramdef>const char *<parameter>buf</parameter></paramdef>
  19. <paramdef>size_t <parameter>count</parameter></paramdef>
  20. </funcprototype>
  21. <funcprototype>
  22. <funcdef>int <function>ne_set_request_body_fd</function></funcdef>
  23. <paramdef>ne_request *<parameter>req</parameter></paramdef>
  24. <paramdef>int <parameter>fd</parameter></paramdef>
  25. <paramdef>ne_off_t <parameter>begin</parameter></paramdef>
  26. <paramdef>ne_off_t <parameter>length</parameter></paramdef>
  27. </funcprototype>
  28. <funcprototype>
  29. <funcdef>typedef ssize_t (*<function>ne_provide_body</function>)</funcdef>
  30. <paramdef>void *<parameter>userdata</parameter></paramdef>
  31. <paramdef>char *<parameter>data</parameter></paramdef>
  32. <paramdef>size_t <parameter>buflen</parameter></paramdef>
  33. </funcprototype>
  34. <funcprototype>
  35. <funcdef>int <function>ne_set_request_body_provider</function></funcdef>
  36. <paramdef>ne_request *<parameter>req</parameter></paramdef>
  37. <paramdef>ne_off_t <parameter>length</parameter></paramdef>
  38. <paramdef>ne_provide_body <parameter>provider</parameter></paramdef>
  39. <paramdef>void *<parameter>userdata</parameter></paramdef>
  40. </funcprototype>
  41. </funcsynopsis>
  42. </refsynopsisdiv>
  43. <refsect1>
  44. <title>Description</title>
  45. <para>The <function>ne_set_request_body_buffer</function>
  46. function specifies that a message body should be included with the
  47. body, which is stored in the <parameter>count</parameter> bytes buffer
  48. <parameter>buf</parameter>.</para>
  49. <para>The <function>ne_set_request_body_fd</function> function
  50. can be used to include a message body with a request which is read
  51. from a file descriptor. The body is read from the file descriptor
  52. <parameter>fd</parameter>, which must be a associated with a seekable
  53. file (not a pipe, socket, or FIFO). <parameter>count</parameter>
  54. bytes are read, beginning at offset <parameter>begin</parameter>
  55. (hence, passing <parameter>begin</parameter> as zero means the body is read
  56. from the beginning of the file).</para>
  57. <para>For both above functions, the source of the request
  58. body must survive until the request has been dispatched;
  59. neither the memory buffer passed to
  60. <function>ne_set_request_body_buffer</function> nor the file
  61. descriptor passed to
  62. <function>ne_set_request_body_fd</function> are copied
  63. internally.</para>
  64. <para>The <function>ne_set_request_body_provider</function>
  65. function can be used to include a message body with a request
  66. which is provided by a callback function. The body length
  67. passed in the <parameter>length</parameter> paramater must be
  68. positive, or if a chunked request body is required, as covered
  69. below, <literal>-1</literal> can be used.</para>
  70. <para>Before sending the body, the callback is invoked once
  71. with the <parameter>buflen</parameter> parameter as
  72. <literal>0</literal>. The body is then read by invoking the
  73. callback repeatedly until it returns <literal>0</literal>
  74. indicating the end-of-body. The callback return value must be
  75. as follows:
  76. <variablelist>
  77. <varlistentry>
  78. <term>less than <literal>0</literal></term>
  79. <listitem><simpara>An error; the request will be
  80. aborted. The session error string must be set via
  81. <function>ne_set_error</function>.</simpara>
  82. </listitem>
  83. </varlistentry>
  84. <varlistentry>
  85. <term><literal>0</literal></term>
  86. <listitem><simpara>End of body.</simpara>
  87. </listitem>
  88. </varlistentry>
  89. <varlistentry>
  90. <term>between <literal>0</literal> and
  91. <constant>buflen</constant></term>
  92. <listitem><simpara>Number of bytes of request body data.</simpara>
  93. </listitem>
  94. </varlistentry>
  95. </variablelist></para>
  96. <refsect2>
  97. <title>Chunked request bodies</title>
  98. <para>Chunked request bodies are only sent when
  99. <function>ne_set_request_body_provider</function> is used
  100. and <literal>-1</literal> is passed as the
  101. <parameter>length</parameter>. In this case, the length of
  102. the request body does not have to be determined ahead of
  103. time. The end of the request body is indicated by returning
  104. <literal>0</literal> from the callback function.</para>
  105. <para>Before using a chunked request body, the caller must
  106. determine that HTTP/1.1 is supported (by the origin server
  107. and any HTTP proxy server configured). This can be done by
  108. testing that <function>ne_version_pre_http11</function>
  109. returns zero after performing an <literal>OPTIONS</literal>
  110. or <literal>HEAD</literal> request.</para>
  111. </refsect2>
  112. </refsect1>
  113. <refsect1>
  114. <title>See also</title>
  115. <para><xref linkend="ne_request_create"/>, <xref
  116. linkend="ne_set_error"/></para>
  117. </refsect1>
  118. </refentry>