ne_request_create.3 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. '\" t
  2. .\" Title: ne_request_create
  3. .\" Author:
  4. .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
  5. .\" Date: 23 November 2025
  6. .\" Manual: neon API reference
  7. .\" Source: neon 0.36.0
  8. .\" Language: English
  9. .\"
  10. .TH "NE_REQUEST_CREATE" "3" "23 November 2025" "neon 0.36.0" "neon API reference"
  11. .\" -----------------------------------------------------------------
  12. .\" * Define some portability stuff
  13. .\" -----------------------------------------------------------------
  14. .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  15. .\" http://bugs.debian.org/507673
  16. .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
  17. .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18. .ie \n(.g .ds Aq \(aq
  19. .el .ds Aq '
  20. .\" -----------------------------------------------------------------
  21. .\" * set default formatting
  22. .\" -----------------------------------------------------------------
  23. .\" disable hyphenation
  24. .nh
  25. .\" disable justification (adjust text to left margin only)
  26. .ad l
  27. .\" -----------------------------------------------------------------
  28. .\" * MAIN CONTENT STARTS HERE *
  29. .\" -----------------------------------------------------------------
  30. .SH "NAME"
  31. ne_request_create, ne_request_dispatch, ne_request_destroy \- low\-level HTTP request handling
  32. .SH "SYNOPSIS"
  33. .sp
  34. .ft B
  35. .nf
  36. #include <ne_request\&.h>
  37. .fi
  38. .ft
  39. .HP \w'ne_request\ *ne_request_create('u
  40. .BI "ne_request *ne_request_create(ne_session\ *" "session" ", const\ char\ *" "method" ", const\ char\ *" "target" ");"
  41. .HP \w'int\ ne_request_dispatch('u
  42. .BI "int ne_request_dispatch(ne_request\ *" "req" ");"
  43. .HP \w'void\ ne_request_destroy('u
  44. .BI "void ne_request_destroy(ne_request\ *" "req" ");"
  45. .SH "DESCRIPTION"
  46. .PP
  47. The
  48. \fBne_request\fR
  49. object represents an HTTP request and the associated response\&. The
  50. \fBne_request_create\fR
  51. function creates a new request object for the given
  52. \fIsession\fR\&. The target resource for the request is identified by the
  53. \fItarget\fR, parameter, and the method to be performed on that resource via the
  54. \fImethod\fR
  55. parameter\&.
  56. .PP
  57. The
  58. \fItarget\fR
  59. string used must conform to the
  60. request\-target
  61. definition given in
  62. \m[blue]\fBRFC 9112\fR\m[]\&\s-2\u[1]\d\s+2\&. Usually this will take the
  63. abolute\-path
  64. form, which optionally includes a query string\&.
  65. .PP
  66. To
  67. \fIdispatch\fR
  68. a request, and process the response, the
  69. \fBne_request_dispatch\fR
  70. function can be used\&. An alternative is to use the (more complex, but more flexible) combination of the
  71. \fBne_begin_request\fR,
  72. \fBne_end_request\fR, and
  73. \fBne_read_response_block\fR
  74. functions; see
  75. \fBne_begin_request\fR\&.
  76. \fIDispatching\fR
  77. a request may require multiple iterations of a request being sent and response received, for example if authentication is used (see
  78. ne_set_server_auth), or if a persistent connection times out; this is handled internally by
  79. \fBne_request_dispatch\fR\&.
  80. .PP
  81. To add extra headers in the request, the functions
  82. ne_add_request_header
  83. and
  84. ne_print_request_header
  85. can be used\&. To include a message body with the request, one of the functions
  86. \fBne_set_request_body_buffer\fR,
  87. \fBne_set_request_body_fd\fR, or
  88. \fBne_set_request_body_provider\fR
  89. can be used\&.
  90. .PP
  91. The return value of
  92. \fBne_request_dispatch\fR
  93. indicates merely whether the request was sent and the response read successfully\&. To discover the result of the operation,
  94. ne_get_status, along with any processing of the response headers and message body\&.
  95. .PP
  96. A request can only be dispatched once: calling
  97. \fBne_request_dispatch\fR
  98. more than once on a single
  99. \fBne_request\fR
  100. object produces undefined behaviour\&. Once all processing associated with the request object is complete, use the
  101. \fBne_request_destroy\fR
  102. function to destroy the resources associated with it\&. Any subsequent use of the request object produces undefined behaviour\&.
  103. .PP
  104. Request methods are assumed to be
  105. \m[blue]\fBidempotent\fR\m[]\&\s-2\u[2]\d\s+2
  106. by default\&. For a request using a non\-idempotent method such as
  107. POST, the
  108. NE_REQFLAG_IDEMPOTENT
  109. flag must be disabled using
  110. ne_set_request_flag\&.
  111. .SH "RETURN VALUE"
  112. .PP
  113. The
  114. \fBne_request_create\fR
  115. function returns a pointer to a request object (and never
  116. NULL)\&.
  117. .PP
  118. The
  119. \fBne_request_dispatch\fR
  120. function returns zero if the request was dispatched successfully, and a non\-zero error code code otherwise, as described in the following section\&.
  121. .SH "ERROR CODES"
  122. .PP
  123. Error codes have a non\-zero value, and correspond to an
  124. NE_*
  125. macro definition, as listed below\&. Future versions of neon may introduce additional error code definitions\&. Functions which return an error code and have an associated session object set the session error string (see
  126. ne_get_error) unless documented otherwise\&.
  127. .PP
  128. \fBNE_ERROR\fR
  129. .RS 4
  130. Request failed (see session error string)
  131. .RE
  132. .PP
  133. \fBNE_LOOKUP\fR
  134. .RS 4
  135. The DNS lookup for the server (or proxy server) failed\&.
  136. .RE
  137. .PP
  138. \fBNE_AUTH\fR
  139. .RS 4
  140. Authentication failed on the server\&.
  141. .RE
  142. .PP
  143. \fBNE_PROXYAUTH\fR
  144. .RS 4
  145. Authentication failed on the proxy server\&.
  146. .RE
  147. .PP
  148. \fBNE_CONNECT\fR
  149. .RS 4
  150. A connection to the server could not be established\&.
  151. .RE
  152. .PP
  153. \fBNE_TIMEOUT\fR
  154. .RS 4
  155. A timeout occurred while waiting for the server to respond\&.
  156. .RE
  157. .PP
  158. \fBNE_REDIRECT\fR
  159. .RS 4
  160. A valid redirect was retuerned\&.
  161. \fINote:\fR
  162. Only returned if redirect handling is registered for the session using
  163. ne_redirect_register\&.
  164. .RE
  165. .SH "NOTES"
  166. .PP
  167. The
  168. \fIpath\fR,
  169. \fImethod\fR
  170. and
  171. \fItarget\fR
  172. parameters of
  173. \fBne_request_create\fR
  174. are used directly in request data without validation, so must not be taken from untrusted sources\&. For example, allowing insertion of unescaped CR, LF or other control characters in these parameters may result in unexpected or insecure behaviour\&.
  175. .PP
  176. neon does not impose any length restrictions on request input data\&.
  177. .SH "EXAMPLE"
  178. .PP
  179. An example of applying a
  180. MKCOL
  181. operation to the resource at the location
  182. http://www\&.example\&.com/foo/bar/:
  183. .sp
  184. .if n \{\
  185. .RS 4
  186. .\}
  187. .nf
  188. ne_session *sess = ne_session_create("http", "www\&.example\&.com", 80);
  189. ne_request *req = ne_request_create(sess, "MKCOL", "/foo/bar/");
  190. if (ne_request_dispatch(req)) {
  191. printf("Request failed: %s\en", ne_get_error(sess));
  192. }
  193. ne_request_destroy(req);
  194. .fi
  195. .if n \{\
  196. .RE
  197. .\}
  198. .SH "SEE ALSO"
  199. .PP
  200. ne_get_error,
  201. ne_set_error,
  202. ne_get_status,
  203. ne_add_request_header,
  204. ne_set_request_body_buffer,
  205. ne_set_request_flag,
  206. ne_redirect_register\&.
  207. .SH "COPYRIGHT"
  208. .br
  209. Copyright \(co 2001-2025 Joe Orton
  210. .br
  211. .SH "REFERENCES"
  212. .IP " 1." 4
  213. RFC 9112
  214. .RS 4
  215. \%https://www.rfc-editor.org/rfc/rfc9112
  216. .RE
  217. .IP " 2." 4
  218. idempotent
  219. .RS 4
  220. \%https://www.rfc-editor.org/rfc/rfc9110.html#name-idempotent-methods
  221. .RE