ne_request_create.3 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. '\" t
  2. .\" Title: ne_request_create
  3. .\" Author:
  4. .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
  5. .\" Date: 15 April 2025
  6. .\" Manual: neon API reference
  7. .\" Source: neon 0.34.2
  8. .\" Language: English
  9. .\"
  10. .TH "NE_REQUEST_CREATE" "3" "15 April 2025" "neon 0.34.2" "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 otherwise\&.
  121. .SH "NOTES"
  122. .PP
  123. The
  124. \fIpath\fR,
  125. \fImethod\fR
  126. and
  127. \fItarget\fR
  128. parameters of
  129. \fBne_request_create\fR
  130. 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\&.
  131. .PP
  132. neon does not impose any length restrictions on request input data\&.
  133. .SH "ERRORS"
  134. .PP
  135. \fBNE_ERROR\fR
  136. .RS 4
  137. Request failed (see session error string)
  138. .RE
  139. .PP
  140. \fBNE_LOOKUP\fR
  141. .RS 4
  142. The DNS lookup for the server (or proxy server) failed\&.
  143. .RE
  144. .PP
  145. \fBNE_AUTH\fR
  146. .RS 4
  147. Authentication failed on the server\&.
  148. .RE
  149. .PP
  150. \fBNE_PROXYAUTH\fR
  151. .RS 4
  152. Authentication failed on the proxy server\&.
  153. .RE
  154. .PP
  155. \fBNE_CONNECT\fR
  156. .RS 4
  157. A connection to the server could not be established\&.
  158. .RE
  159. .PP
  160. \fBNE_TIMEOUT\fR
  161. .RS 4
  162. A timeout occurred while waiting for the server to respond\&.
  163. .RE
  164. .SH "EXAMPLE"
  165. .PP
  166. An example of applying a
  167. MKCOL
  168. operation to the resource at the location
  169. http://www\&.example\&.com/foo/bar/:
  170. .sp
  171. .if n \{\
  172. .RS 4
  173. .\}
  174. .nf
  175. ne_session *sess = ne_session_create("http", "www\&.example\&.com", 80);
  176. ne_request *req = ne_request_create(sess, "MKCOL", "/foo/bar/");
  177. if (ne_request_dispatch(req)) {
  178. printf("Request failed: %s\en", ne_get_error(sess));
  179. }
  180. ne_request_destroy(req);
  181. .fi
  182. .if n \{\
  183. .RE
  184. .\}
  185. .SH "SEE ALSO"
  186. .PP
  187. ne_get_error,
  188. ne_set_error,
  189. ne_get_status,
  190. ne_add_request_header,
  191. ne_set_request_body_buffer,
  192. ne_set_request_flag\&.
  193. .SH "COPYRIGHT"
  194. .br
  195. Copyright \(co 2001-2024 Joe Orton
  196. .br
  197. .SH "REFERENCES"
  198. .IP " 1." 4
  199. RFC 9112
  200. .RS 4
  201. \%https://www.rfc-editor.org/rfc/rfc9112
  202. .RE
  203. .IP " 2." 4
  204. idempotent
  205. .RS 4
  206. \%https://www.rfc-editor.org/rfc/rfc9110.html#name-idempotent-methods
  207. .RE