ne_request_create.3 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. '\" t
  2. .\" Title: ne_request_create
  3. .\" Author:
  4. .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
  5. .\" Date: 21 January 2023
  6. .\" Manual: neon API reference
  7. .\" Source: neon 0.32.5
  8. .\" Language: English
  9. .\"
  10. .TH "NE_REQUEST_CREATE" "3" "21 January 2023" "neon 0.32.5" "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\ *" "path" ");"
  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. \fIpath\fR, and the method to be performed on that resource via the
  54. \fImethod\fR
  55. parameter\&.
  56. .PP
  57. The
  58. \fIpath\fR
  59. string used must conform to the
  60. abs_path
  61. definition given in RFC2396, with an optional "?query" part, and must be URI\-escaped by the caller (for instance, using
  62. \fBne_path_escape\fR)\&. If the string comes from an untrusted source, failure to perform URI\-escaping results in a security vulnerability\&.
  63. .PP
  64. To dispatch a request, and process the response, the
  65. \fBne_request_dispatch\fR
  66. function can be used\&. An alternative is to use the (more complex, but more flexible) combination of the
  67. \fBne_begin_request\fR,
  68. \fBne_end_request\fR, and
  69. \fBne_read_response_block\fR
  70. functions; see
  71. \fBne_begin_request\fR\&.
  72. .PP
  73. To add extra headers in the request, the functions
  74. ne_add_request_header
  75. and
  76. ne_print_request_header
  77. can be used\&. To include a message body with the request, one of the functions
  78. \fBne_set_request_body_buffer\fR,
  79. \fBne_set_request_body_fd\fR, or
  80. \fBne_set_request_body_provider\fR
  81. can be used\&.
  82. .PP
  83. The return value of
  84. \fBne_request_dispatch\fR
  85. indicates merely whether the request was sent and the response read successfully\&. To discover the result of the operation,
  86. ne_get_status, along with any processing of the response headers and message body\&.
  87. .PP
  88. A request can only be dispatched once: calling
  89. \fBne_request_dispatch\fR
  90. more than once on a single
  91. \fBne_request\fR
  92. object produces undefined behaviour\&. Once all processing associated with the request object is complete, use the
  93. \fBne_request_destroy\fR
  94. function to destroy the resources associated with it\&. Any subsequent use of the request object produces undefined behaviour\&.
  95. .PP
  96. For a request with a non\-idempotent method such as
  97. POST, the
  98. NE_REQFLAG_IDEMPOTENT
  99. flag should be disabled; see
  100. ne_set_request_flag\&.
  101. .SH "RETURN VALUE"
  102. .PP
  103. The
  104. \fBne_request_create\fR
  105. function returns a pointer to a request object (and never
  106. NULL)\&.
  107. .PP
  108. The
  109. \fBne_request_dispatch\fR
  110. function returns zero if the request was dispatched successfully, and a non\-zero error code otherwise\&.
  111. .SH "ERRORS"
  112. .PP
  113. \fBNE_ERROR\fR
  114. .RS 4
  115. Request failed (see session error string)
  116. .RE
  117. .PP
  118. \fBNE_LOOKUP\fR
  119. .RS 4
  120. The DNS lookup for the server (or proxy server) failed\&.
  121. .RE
  122. .PP
  123. \fBNE_AUTH\fR
  124. .RS 4
  125. Authentication failed on the server\&.
  126. .RE
  127. .PP
  128. \fBNE_PROXYAUTH\fR
  129. .RS 4
  130. Authentication failed on the proxy server\&.
  131. .RE
  132. .PP
  133. \fBNE_CONNECT\fR
  134. .RS 4
  135. A connection to the server could not be established\&.
  136. .RE
  137. .PP
  138. \fBNE_TIMEOUT\fR
  139. .RS 4
  140. A timeout occurred while waiting for the server to respond\&.
  141. .RE
  142. .SH "EXAMPLE"
  143. .PP
  144. An example of applying a
  145. MKCOL
  146. operation to the resource at the location
  147. http://www\&.example\&.com/foo/bar/:
  148. .sp
  149. .if n \{\
  150. .RS 4
  151. .\}
  152. .nf
  153. ne_session *sess = ne_session_create("http", "www\&.example\&.com", 80);
  154. ne_request *req = ne_request_create(sess, "MKCOL", "/foo/bar/");
  155. if (ne_request_dispatch(req)) {
  156. printf("Request failed: %s\en", ne_get_error(sess));
  157. }
  158. ne_request_destroy(req);
  159. .fi
  160. .if n \{\
  161. .RE
  162. .\}
  163. .SH "SEE ALSO"
  164. .PP
  165. ne_get_error,
  166. ne_set_error,
  167. ne_get_status,
  168. ne_add_request_header,
  169. ne_set_request_body_buffer,
  170. ne_set_request_flag\&.
  171. .SH "AUTHOR"
  172. .PP
  173. \fBJoe Orton\fR
  174. .RS 4
  175. Author.
  176. .RE
  177. .SH "COPYRIGHT"
  178. .br