1 .TH "event2/http.h" 3 "Tue Jan 27 2015" "libevent" \" -*- nroff -*-
7 Basic support for HTTP serving\&.
12 \fC#include <event2/util\&.h>\fP
19 .RI "#define \fBEVHTTP_URI_NONCONFORMANT\fP 0x01"
21 .RI "\fITolerate URIs that do not conform to RFC3986\&. \fP"
23 .RI "#define \fBHTTP_BADMETHOD\fP 405"
25 .RI "\fImethod not allowed for this uri \fP"
27 .RI "#define \fBHTTP_BADREQUEST\fP 400"
29 .RI "\fIinvalid http request was made \fP"
31 .RI "#define \fBHTTP_ENTITYTOOLARGE\fP 413"
34 .RI "#define \fBHTTP_EXPECTATIONFAILED\fP 417"
36 .RI "\fIwe can't handle this expectation \fP"
38 .RI "#define \fBHTTP_INTERNAL\fP 500"
40 .RI "\fIinternal error \fP"
42 .RI "#define \fBHTTP_MOVEPERM\fP 301"
44 .RI "\fIthe uri moved permanently \fP"
46 .RI "#define \fBHTTP_MOVETEMP\fP 302"
48 .RI "\fIthe uri moved temporarily \fP"
50 .RI "#define \fBHTTP_NOCONTENT\fP 204"
52 .RI "\fIrequest does not have content \fP"
54 .RI "#define \fBHTTP_NOTFOUND\fP 404"
56 .RI "\fIcould not find content for uri \fP"
58 .RI "#define \fBHTTP_NOTIMPLEMENTED\fP 501"
60 .RI "\fInot implemented \fP"
62 .RI "#define \fBHTTP_NOTMODIFIED\fP 304"
64 .RI "\fIpage was not modified from last \fP"
66 .RI "#define \fBHTTP_OK\fP 200"
68 .RI "\fIrequest completed ok \fP"
70 .RI "#define \fBHTTP_SERVUNAVAIL\fP 503"
72 .RI "\fIthe server is not available \fP"
78 .RI "enum \fBevhttp_cmd_type\fP { \fBEVHTTP_REQ_GET\fP = 1 << 0, \fBEVHTTP_REQ_POST\fP = 1 << 1, \fBEVHTTP_REQ_HEAD\fP = 1 << 2, \fBEVHTTP_REQ_PUT\fP = 1 << 3, \fBEVHTTP_REQ_DELETE\fP = 1 << 4, \fBEVHTTP_REQ_OPTIONS\fP = 1 << 5, \fBEVHTTP_REQ_TRACE\fP = 1 << 6, \fBEVHTTP_REQ_CONNECT\fP = 1 << 7, \fBEVHTTP_REQ_PATCH\fP = 1 << 8 }"
80 .RI "\fIThe different request types supported by evhttp\&. \fP"
82 .RI "enum \fBevhttp_request_kind\fP { \fBEVHTTP_REQUEST\fP, \fBEVHTTP_RESPONSE\fP }"
84 .RI "\fIa request object can represent either a request or a reply \fP"
90 .RI "int \fBevhttp_accept_socket\fP (struct evhttp *http, \fBevutil_socket_t\fP fd)"
92 .RI "\fIMakes an HTTP server accept connections on the specified socket\&. \fP"
94 .RI "struct evhttp_bound_socket * \fBevhttp_accept_socket_with_handle\fP (struct evhttp *http, \fBevutil_socket_t\fP fd)"
96 .RI "\fILike \fBevhttp_accept_socket()\fP, but returns a handle for referencing the socket\&. \fP"
98 .RI "int \fBevhttp_add_header\fP (struct evkeyvalq *headers, const char *key, const char *value)"
100 .RI "\fIAdds a header to a list of existing headers\&. \fP"
102 .RI "int \fBevhttp_add_server_alias\fP (struct evhttp *http, const char *alias)"
104 .RI "\fIAdd a server alias to an http object\&. \fP"
106 .RI "int \fBevhttp_add_virtual_host\fP (struct evhttp *http, const char *pattern, struct evhttp *vhost)"
108 .RI "\fIAdds a virtual host to the http server\&. \fP"
110 .RI "struct evhttp_bound_socket * \fBevhttp_bind_listener\fP (struct evhttp *http, struct evconnlistener *listener)"
112 .RI "\fIThe most low-level evhttp_bind/accept method: takes an evconnlistener, and returns an evhttp_bound_socket\&. \fP"
114 .RI "int \fBevhttp_bind_socket\fP (struct evhttp *http, const char *address, ev_uint16_t port)"
116 .RI "\fIBinds an HTTP server on the specified address and port\&. \fP"
118 .RI "struct evhttp_bound_socket * \fBevhttp_bind_socket_with_handle\fP (struct evhttp *http, const char *address, ev_uint16_t port)"
120 .RI "\fILike \fBevhttp_bind_socket()\fP, but returns a handle for referencing the socket\&. \fP"
122 .RI "\fBevutil_socket_t\fP \fBevhttp_bound_socket_get_fd\fP (struct evhttp_bound_socket *bound_socket)"
124 .RI "\fIGet the raw file descriptor referenced by an evhttp_bound_socket\&. \fP"
126 .RI "struct evconnlistener * \fBevhttp_bound_socket_get_listener\fP (struct evhttp_bound_socket *bound)"
128 .RI "\fIReturn the listener used to implement a bound socket\&. \fP"
130 .RI "void \fBevhttp_cancel_request\fP (struct evhttp_request *req)"
132 .RI "\fICancels a pending HTTP request\&. \fP"
134 .RI "void \fBevhttp_clear_headers\fP (struct evkeyvalq *headers)"
136 .RI "\fIRemoves all headers from the header list\&. \fP"
138 .RI "struct evhttp_connection * \fBevhttp_connection_base_new\fP (struct \fBevent_base\fP *base, struct evdns_base *dnsbase, const char *address, unsigned short port)"
140 .RI "\fIA connection object that can be used to for making HTTP requests\&. \fP"
142 .RI "void \fBevhttp_connection_free\fP (struct evhttp_connection *evcon)"
144 .RI "\fIFrees an http connection\&. \fP"
146 .RI "struct \fBevent_base\fP * \fBevhttp_connection_get_base\fP (struct evhttp_connection *req)"
148 .RI "\fIReturns the underlying \fBevent_base\fP for this connection\&. \fP"
150 .RI "struct \fBbufferevent\fP * \fBevhttp_connection_get_bufferevent\fP (struct evhttp_connection *evcon)"
152 .RI "\fIReturn the bufferevent that an evhttp_connection is using\&. \fP"
154 .RI "void \fBevhttp_connection_get_peer\fP (struct evhttp_connection *evcon, char **address, ev_uint16_t *port)"
156 .RI "\fIGet the remote address and port associated with this connection\&. \fP"
158 .RI "void \fBevhttp_connection_set_closecb\fP (struct evhttp_connection *evcon, void(*)(struct evhttp_connection *, void *), void *)"
160 .RI "\fISet a callback for connection close\&. \fP"
162 .RI "void \fBevhttp_connection_set_local_address\fP (struct evhttp_connection *evcon, const char *address)"
164 .RI "\fIsets the ip address from which http connections are made \fP"
166 .RI "void \fBevhttp_connection_set_local_port\fP (struct evhttp_connection *evcon, ev_uint16_t port)"
168 .RI "\fIsets the local port from which http connections are made \fP"
170 .RI "void \fBevhttp_connection_set_max_body_size\fP (struct evhttp_connection *evcon, ev_ssize_t new_max_body_size)"
173 .RI "void \fBevhttp_connection_set_max_headers_size\fP (struct evhttp_connection *evcon, ev_ssize_t new_max_headers_size)"
176 .RI "void \fBevhttp_connection_set_retries\fP (struct evhttp_connection *evcon, int retry_max)"
178 .RI "\fISets the retry limit for this connection - -1 repeats indefinitely\&. \fP"
180 .RI "void \fBevhttp_connection_set_timeout\fP (struct evhttp_connection *evcon, int timeout_in_secs)"
182 .RI "\fISets the timeout for events related to this connection\&. \fP"
184 .RI "char * \fBevhttp_decode_uri\fP (const char *uri)"
186 .RI "\fIHelper function to sort of decode a URI-encoded string\&. \fP"
188 .RI "void \fBevhttp_del_accept_socket\fP (struct evhttp *http, struct evhttp_bound_socket *bound_socket)"
190 .RI "\fIMakes an HTTP server stop accepting connections on the specified socket\&. \fP"
192 .RI "int \fBevhttp_del_cb\fP (struct evhttp *, const char *)"
194 .RI "\fIRemoves the callback for a specified URI\&. \fP"
196 .RI "char * \fBevhttp_encode_uri\fP (const char *str)"
198 .RI "\fIHelper function to encode a string for inclusion in a URI\&. \fP"
200 .RI "const char * \fBevhttp_find_header\fP (const struct evkeyvalq *headers, const char *key)"
202 .RI "\fIFinds the value belonging to a header\&. \fP"
204 .RI "void \fBevhttp_free\fP (struct evhttp *http)"
206 .RI "\fIFree the previously created HTTP server\&. \fP"
208 .RI "char * \fBevhttp_htmlescape\fP (const char *html)"
210 .RI "\fIEscape HTML character entities in a string\&. \fP"
212 .RI "int \fBevhttp_make_request\fP (struct evhttp_connection *evcon, struct evhttp_request *req, enum \fBevhttp_cmd_type\fP type, const char *uri)"
214 .RI "\fIMake an HTTP request over the specified connection\&. \fP"
216 .RI "struct evhttp * \fBevhttp_new\fP (struct \fBevent_base\fP *base)"
218 .RI "\fICreate a new HTTP server\&. \fP"
220 .RI "int \fBevhttp_parse_query\fP (const char *uri, struct evkeyvalq *headers)"
222 .RI "\fIHelper function to parse out arguments in a query\&. \fP"
224 .RI "int \fBevhttp_parse_query_str\fP (const char *uri, struct evkeyvalq *headers)"
226 .RI "\fIHelper function to parse out arguments from the query portion of an HTTP URI\&. \fP"
228 .RI "int \fBevhttp_remove_header\fP (struct evkeyvalq *headers, const char *key)"
230 .RI "\fIRemoves a header from a list of existing headers\&. \fP"
232 .RI "int \fBevhttp_remove_server_alias\fP (struct evhttp *http, const char *alias)"
234 .RI "\fIRemove a server alias from an http object\&. \fP"
236 .RI "int \fBevhttp_remove_virtual_host\fP (struct evhttp *http, struct evhttp *vhost)"
238 .RI "\fIRemoves a virtual host from the http server\&. \fP"
240 .RI "void \fBevhttp_request_free\fP (struct evhttp_request *req)"
242 .RI "\fIFrees the request object and removes associated events\&. \fP"
244 .RI "enum \fBevhttp_cmd_type\fP \fBevhttp_request_get_command\fP (const struct evhttp_request *req)"
246 .RI "\fIReturns the request command\&. \fP"
248 .RI "struct evhttp_connection * \fBevhttp_request_get_connection\fP (struct evhttp_request *req)"
250 .RI "\fIReturns the connection object associated with the request or NULL\&. \fP"
252 .RI "const struct evhttp_uri * \fBevhttp_request_get_evhttp_uri\fP (const struct evhttp_request *req)"
254 .RI "\fIReturns the request URI (parsed) \fP"
256 .RI "const char * \fBevhttp_request_get_host\fP (struct evhttp_request *req)"
258 .RI "\fIReturns the host associated with the request\&. \fP"
260 .RI "struct \fBevbuffer\fP * \fBevhttp_request_get_input_buffer\fP (struct evhttp_request *req)"
262 .RI "\fIReturns the input buffer\&. \fP"
264 .RI "struct evkeyvalq * \fBevhttp_request_get_input_headers\fP (struct evhttp_request *req)"
266 .RI "\fIReturns the input headers\&. \fP"
268 .RI "struct \fBevbuffer\fP * \fBevhttp_request_get_output_buffer\fP (struct evhttp_request *req)"
270 .RI "\fIReturns the output buffer\&. \fP"
272 .RI "struct evkeyvalq * \fBevhttp_request_get_output_headers\fP (struct evhttp_request *req)"
274 .RI "\fIReturns the output headers\&. \fP"
276 .RI "int \fBevhttp_request_get_response_code\fP (const struct evhttp_request *req)"
279 .RI "const char * \fBevhttp_request_get_uri\fP (const struct evhttp_request *req)"
281 .RI "\fIReturns the request URI\&. \fP"
283 .RI "int \fBevhttp_request_is_owned\fP (struct evhttp_request *req)"
285 .RI "\fIReturns 1 if the request is owned by the user\&. \fP"
287 .RI "struct evhttp_request * \fBevhttp_request_new\fP (void(*cb)(struct evhttp_request *, void *), void *arg)"
289 .RI "\fICreates a new request object that needs to be filled in with the request parameters\&. \fP"
291 .RI "void \fBevhttp_request_own\fP (struct evhttp_request *req)"
293 .RI "\fITakes ownership of the request object\&. \fP"
295 .RI "void \fBevhttp_request_set_chunked_cb\fP (struct evhttp_request *, void(*cb)(struct evhttp_request *, void *))"
297 .RI "\fIEnable delivery of chunks to requestor\&. \fP"
299 .RI "void \fBevhttp_send_error\fP (struct evhttp_request *req, int error, const char *reason)"
301 .RI "\fISend an HTML error message to the client\&. \fP"
303 .RI "void \fBevhttp_send_reply\fP (struct evhttp_request *req, int code, const char *reason, struct \fBevbuffer\fP *databuf)"
305 .RI "\fISend an HTML reply to the client\&. \fP"
307 .RI "void \fBevhttp_send_reply_chunk\fP (struct evhttp_request *req, struct \fBevbuffer\fP *databuf)"
309 .RI "\fISend another data chunk as part of an ongoing chunked reply\&. \fP"
311 .RI "void \fBevhttp_send_reply_end\fP (struct evhttp_request *req)"
313 .RI "\fIComplete a chunked reply, freeing the request as appropriate\&. \fP"
315 .RI "void \fBevhttp_send_reply_start\fP (struct evhttp_request *req, int code, const char *reason)"
317 .RI "\fIInitiate a reply that uses Transfer-Encoding chunked\&. \fP"
319 .RI "void \fBevhttp_set_allowed_methods\fP (struct evhttp *http, ev_uint16_t methods)"
321 .RI "\fISets the what HTTP methods are supported in requests accepted by this server, and passed to user callbacks\&. \fP"
323 .RI "int \fBevhttp_set_cb\fP (struct evhttp *http, const char *path, void(*cb)(struct evhttp_request *, void *), void *cb_arg)"
325 .RI "\fISet a callback for a specified URI\&. \fP"
327 .RI "void \fBevhttp_set_gencb\fP (struct evhttp *http, void(*cb)(struct evhttp_request *, void *), void *arg)"
329 .RI "\fISet a callback for all requests that are not caught by specific callbacks\&. \fP"
331 .RI "void \fBevhttp_set_max_body_size\fP (struct evhttp *http, ev_ssize_t max_body_size)"
333 .RI "\fIXXX Document\&. \fP"
335 .RI "void \fBevhttp_set_max_headers_size\fP (struct evhttp *http, ev_ssize_t max_headers_size)"
337 .RI "\fIXXX Document\&. \fP"
339 .RI "void \fBevhttp_set_timeout\fP (struct evhttp *http, int timeout_in_secs)"
341 .RI "\fISet the timeout for an HTTP request\&. \fP"
343 .RI "void \fBevhttp_uri_free\fP (struct evhttp_uri *uri)"
345 .RI "\fIFree all memory allocated for a parsed uri\&. \fP"
347 .RI "const char * \fBevhttp_uri_get_fragment\fP (const struct evhttp_uri *uri)"
349 .RI "\fIReturn the fragment part of an evhttp_uri (excluding the leading '#'), or NULL if it has no fragment set\&. \fP"
351 .RI "const char * \fBevhttp_uri_get_host\fP (const struct evhttp_uri *uri)"
353 .RI "\fIReturn the host part of an evhttp_uri, or NULL if it has no host set\&. \fP"
355 .RI "const char * \fBevhttp_uri_get_path\fP (const struct evhttp_uri *uri)"
357 .RI "\fIReturn the path part of an evhttp_uri, or NULL if it has no path set\&. \fP"
359 .RI "int \fBevhttp_uri_get_port\fP (const struct evhttp_uri *uri)"
361 .RI "\fIReturn the port part of an evhttp_uri, or -1 if there is no port set\&. \fP"
363 .RI "const char * \fBevhttp_uri_get_query\fP (const struct evhttp_uri *uri)"
365 .RI "\fIReturn the query part of an evhttp_uri (excluding the leading '?'), or NULL if it has no query set\&. \fP"
367 .RI "const char * \fBevhttp_uri_get_scheme\fP (const struct evhttp_uri *uri)"
369 .RI "\fIReturn the scheme of an evhttp_uri, or NULL if there is no scheme has been set and the evhttp_uri contains a Relative-Ref\&. \fP"
371 .RI "const char * \fBevhttp_uri_get_userinfo\fP (const struct evhttp_uri *uri)"
373 .RI "\fIReturn the userinfo part of an evhttp_uri, or NULL if it has no userinfo set\&. \fP"
375 .RI "char * \fBevhttp_uri_join\fP (struct evhttp_uri *uri, char *buf, size_t limit)"
377 .RI "\fIJoin together the uri parts from parsed data to form a URI-Reference\&. \fP"
379 .RI "struct evhttp_uri * \fBevhttp_uri_new\fP (void)"
381 .RI "\fIReturn a new empty evhttp_uri with no fields set\&. \fP"
383 .RI "struct evhttp_uri * \fBevhttp_uri_parse\fP (const char *source_uri)"
385 .RI "\fIAlias for evhttp_uri_parse_with_flags(source_uri, 0) \fP"
387 .RI "struct evhttp_uri * \fBevhttp_uri_parse_with_flags\fP (const char *source_uri, unsigned flags)"
389 .RI "\fIHelper function to parse a URI-Reference as specified by RFC3986\&. \fP"
391 .RI "void \fBevhttp_uri_set_flags\fP (struct evhttp_uri *uri, unsigned flags)"
393 .RI "\fIChanges the flags set on a given URI\&. \fP"
395 .RI "int \fBevhttp_uri_set_fragment\fP (struct evhttp_uri *uri, const char *fragment)"
397 .RI "\fISet the fragment of an evhttp_uri, or clear the fragment if fragment==NULL\&. \fP"
399 .RI "int \fBevhttp_uri_set_host\fP (struct evhttp_uri *uri, const char *host)"
401 .RI "\fISet the host of an evhttp_uri, or clear the host if host==NULL\&. \fP"
403 .RI "int \fBevhttp_uri_set_path\fP (struct evhttp_uri *uri, const char *path)"
405 .RI "\fISet the path of an evhttp_uri, or clear the path if path==NULL\&. \fP"
407 .RI "int \fBevhttp_uri_set_port\fP (struct evhttp_uri *uri, int port)"
409 .RI "\fISet the port of an evhttp_uri, or clear the port if port==-1\&. \fP"
411 .RI "int \fBevhttp_uri_set_query\fP (struct evhttp_uri *uri, const char *query)"
413 .RI "\fISet the query of an evhttp_uri, or clear the query if query==NULL\&. \fP"
415 .RI "int \fBevhttp_uri_set_scheme\fP (struct evhttp_uri *uri, const char *scheme)"
417 .RI "\fISet the scheme of an evhttp_uri, or clear the scheme if scheme==NULL\&. \fP"
419 .RI "int \fBevhttp_uri_set_userinfo\fP (struct evhttp_uri *uri, const char *userinfo)"
421 .RI "\fISet the userinfo of an evhttp_uri, or clear the userinfo if userinfo==NULL\&. \fP"
423 .RI "char * \fBevhttp_uridecode\fP (const char *uri, int decode_plus, size_t *size_out)"
425 .RI "\fIHelper function to decode a URI-escaped string or HTTP parameter\&. \fP"
427 .RI "char * \fBevhttp_uriencode\fP (const char *str, ev_ssize_t size, int space_to_plus)"
429 .RI "\fIAs evhttp_encode_uri, but if 'size' is nonnegative, treat the string as being 'size' bytes long\&. \fP"
431 .SH "Detailed Description"
433 Basic support for HTTP serving\&.
435 As Libevent is a library for dealing with event notification and most interesting applications are networked today, I have often found the need to write HTTP code\&. The following prototypes and definitions provide an application with a minimal interface for making HTTP requests and for creating a very simple HTTP server\&.
436 .SH "Macro Definition Documentation"
438 .SS "#define EVHTTP_URI_NONCONFORMANT 0x01"
441 Tolerate URIs that do not conform to RFC3986\&. Unfortunately, some HTTP clients generate URIs that, according to RFC3986, are not conformant URIs\&. If you need to support these URIs, you can do so by passing this flag to evhttp_uri_parse_with_flags\&.
443 Currently, these changes are:
447 Nonconformant URIs are allowed to contain otherwise unreasonable characters in their path, query, and fragment components\&.
450 .SH "Enumeration Type Documentation"
452 .SS "enum \fBevhttp_cmd_type\fP"
455 The different request types supported by evhttp\&. These are as specified in RFC2616, except for PATCH which is specified by RFC5789\&.
457 By default, only some of these methods are accepted and passed to user callbacks; use \fBevhttp_set_allowed_methods()\fP to change which methods are allowed\&.
458 .SH "Function Documentation"
460 .SS "int evhttp_accept_socket (struct evhttp *http, \fBevutil_socket_t\fPfd)"
463 Makes an HTTP server accept connections on the specified socket\&. This may be useful to create a socket and then fork multiple instances of an http server, or when a socket has been communicated via file descriptor passing in situations where an http servers does not have permissions to bind to a low-numbered port\&.
465 Can be called multiple times to have the http server listen to multiple different sockets\&.
469 \fIhttp\fP a pointer to an evhttp object
471 \fIfd\fP a socket fd that is ready for accepting connections
476 0 on success, -1 on failure\&.
481 \fBevhttp_bind_socket()\fP
485 .SS "struct evhttp_bound_socket* evhttp_accept_socket_with_handle (struct evhttp *http, \fBevutil_socket_t\fPfd)"
488 Like \fBevhttp_accept_socket()\fP, but returns a handle for referencing the socket\&. The returned pointer is not valid after \fIhttp\fP is freed\&.
492 \fIhttp\fP a pointer to an evhttp object
494 \fIfd\fP a socket fd that is ready for accepting connections
499 Handle for the socket on success, NULL on failure\&.
504 \fBevhttp_accept_socket()\fP, \fBevhttp_del_accept_socket()\fP
508 .SS "int evhttp_add_header (struct evkeyvalq *headers, const char *key, const char *value)"
511 Adds a header to a list of existing headers\&.
515 \fIheaders\fP the evkeyvalq object to which to add a header
517 \fIkey\fP the name of the header
519 \fIvalue\fP the value belonging to the header
524 0 on success, -1 otherwise\&.
529 \fBevhttp_find_header()\fP, \fBevhttp_clear_headers()\fP
533 .SS "int evhttp_add_server_alias (struct evhttp *http, const char *alias)"
536 Add a server alias to an http object\&. The http object can be a virtual host or the main server\&.
540 \fIhttp\fP the evhttp object
542 \fIalias\fP the alias to add
547 evhttp_add_remove_alias()
551 .SS "int evhttp_add_virtual_host (struct evhttp *http, const char *pattern, struct evhttp *vhost)"
554 Adds a virtual host to the http server\&. A virtual host is a newly initialized evhttp object that has request callbacks set on it via \fBevhttp_set_cb()\fP or \fBevhttp_set_gencb()\fP\&. It most not have any listing sockets associated with it\&.
556 If the virtual host has not been removed by the time that \fBevhttp_free()\fP is called on the main http server, it will be automatically freed, too\&.
558 It is possible to have hierarchical vhosts\&. For example: A vhost with the pattern *\&.example\&.com may have other vhosts with patterns foo\&.example\&.com and bar\&.example\&.com associated with it\&.
562 \fIhttp\fP the evhttp object to which to add a virtual host
564 \fIpattern\fP the glob pattern against which the hostname is matched\&. The match is case insensitive and follows otherwise regular shell matching\&.
566 \fIvhost\fP the virtual host to add the regular http server\&.
571 0 on success, -1 on failure
576 \fBevhttp_remove_virtual_host()\fP
580 .SS "struct evhttp_bound_socket* evhttp_bind_listener (struct evhttp *http, struct evconnlistener *listener)"
583 The most low-level evhttp_bind/accept method: takes an evconnlistener, and returns an evhttp_bound_socket\&. The listener will be freed when the bound socket is freed\&.
584 .SS "int evhttp_bind_socket (struct evhttp *http, const char *address, ev_uint16_tport)"
587 Binds an HTTP server on the specified address and port\&. Can be called multiple times to bind the same http server to multiple different ports\&.
591 \fIhttp\fP a pointer to an evhttp object
593 \fIaddress\fP a string containing the IP address to listen(2) on
595 \fIport\fP the port number to listen on
600 0 on success, -1 on failure\&.
605 \fBevhttp_accept_socket()\fP
609 .SS "struct evhttp_bound_socket* evhttp_bind_socket_with_handle (struct evhttp *http, const char *address, ev_uint16_tport)"
612 Like \fBevhttp_bind_socket()\fP, but returns a handle for referencing the socket\&. The returned pointer is not valid after \fIhttp\fP is freed\&.
616 \fIhttp\fP a pointer to an evhttp object
618 \fIaddress\fP a string containing the IP address to listen(2) on
620 \fIport\fP the port number to listen on
625 Handle for the socket on success, NULL on failure\&.
630 \fBevhttp_bind_socket()\fP, \fBevhttp_del_accept_socket()\fP
634 .SS "\fBevutil_socket_t\fP evhttp_bound_socket_get_fd (struct evhttp_bound_socket *bound_socket)"
637 Get the raw file descriptor referenced by an evhttp_bound_socket\&.
641 \fIbound_socket\fP a handle returned by evhttp_{bind,accept}_socket_with_handle
646 the file descriptor used by the bound socket
651 \fBevhttp_bind_socket_with_handle()\fP, \fBevhttp_accept_socket_with_handle()\fP
655 .SS "void evhttp_cancel_request (struct evhttp_request *req)"
658 Cancels a pending HTTP request\&. Cancels an ongoing HTTP request\&. The callback associated with this request is not executed and the request object is freed\&. If the request is currently being processed, e\&.g\&. it is ongoing, the corresponding evhttp_connection object is going to get reset\&.
660 A request cannot be canceled if its callback has executed already\&. A request may be canceled reentrantly from its chunked callback\&.
664 \fIreq\fP the evhttp_request to cancel; req becomes invalid after this call\&.
668 .SS "void evhttp_clear_headers (struct evkeyvalq *headers)"
671 Removes all headers from the header list\&.
675 \fIheaders\fP the evkeyvalq object from which to remove all headers
679 .SS "struct evhttp_connection* evhttp_connection_base_new (struct \fBevent_base\fP *base, struct evdns_base *dnsbase, const char *address, unsigned shortport)"
682 A connection object that can be used to for making HTTP requests\&. The connection object tries to resolve address and establish the connection when it is given an http request object\&.
686 \fIbase\fP the \fBevent_base\fP to use for handling the connection
688 \fIdnsbase\fP the dns_base to use for resolving host names; if not specified host name resolution will block\&.
690 \fIaddress\fP the address to which to connect
692 \fIport\fP the port to connect to
697 an evhttp_connection object that can be used for making requests
701 .SS "void evhttp_connection_get_peer (struct evhttp_connection *evcon, char **address, ev_uint16_t *port)"
704 Get the remote address and port associated with this connection\&.
705 .SS "void evhttp_connection_set_closecb (struct evhttp_connection *evcon, void(*)(struct evhttp_connection *, void *), void *)"
708 Set a callback for connection close\&.
709 .SS "char* evhttp_decode_uri (const char *uri)"
712 Helper function to sort of decode a URI-encoded string\&. Unlike evhttp_get_decoded_uri, it decodes all plus characters that appear \fIafter\fP the first question mark character, but no plusses that occur before\&. This is not a good way to decode URIs in whole or in part\&.
714 The returned string must be freed by the caller
718 This function is deprecated; you probably want to use evhttp_get_decoded_uri instead\&.
724 \fIuri\fP an encoded URI
729 a newly allocated unencoded URI or NULL on failure
733 .SS "void evhttp_del_accept_socket (struct evhttp *http, struct evhttp_bound_socket *bound_socket)"
736 Makes an HTTP server stop accepting connections on the specified socket\&. This may be useful when a socket has been sent via file descriptor passing and is no longer needed by the current process\&.
738 If you created this bound socket with evhttp_bind_socket_with_handle or evhttp_accept_socket_with_handle, this function closes the fd you provided\&. If you created this bound socket with evhttp_bind_listener, this function frees the listener you provided\&.
740 \fIbound_socket\fP is an invalid pointer after this call returns\&.
744 \fIhttp\fP a pointer to an evhttp object
746 \fIbound_socket\fP a handle returned by evhttp_{bind,accept}_socket_with_handle
751 \fBevhttp_bind_socket_with_handle()\fP, \fBevhttp_accept_socket_with_handle()\fP
755 .SS "char* evhttp_encode_uri (const char *str)"
758 Helper function to encode a string for inclusion in a URI\&. All characters are replaced by their hex-escaped (%22) equivalents, except for characters explicitly unreserved by RFC3986 -- that is, ASCII alphanumeric characters, hyphen, dot, underscore, and tilde\&.
760 The returned string must be freed by the caller\&.
764 \fIstr\fP an unencoded string
769 a newly allocated URI-encoded string or NULL on failure
773 .SS "const char* evhttp_find_header (const struct evkeyvalq *headers, const char *key)"
776 Finds the value belonging to a header\&.
780 \fIheaders\fP the evkeyvalq object in which to find the header
782 \fIkey\fP the name of the header to find
787 a pointer to the value for the header or NULL if the header count not be found\&.
792 \fBevhttp_add_header()\fP, \fBevhttp_remove_header()\fP
796 .SS "void evhttp_free (struct evhttp *http)"
799 Free the previously created HTTP server\&. Works only if no requests are currently being served\&.
803 \fIhttp\fP the evhttp server object to be freed
812 .SS "char* evhttp_htmlescape (const char *html)"
815 Escape HTML character entities in a string\&. Replaces <, >, ", ' and & with <, >, ", ' and & correspondingly\&.
817 The returned string needs to be freed by the caller\&.
821 \fIhtml\fP an unescaped HTML string
826 an escaped HTML string or NULL on error
830 .SS "int evhttp_make_request (struct evhttp_connection *evcon, struct evhttp_request *req, enum \fBevhttp_cmd_type\fPtype, const char *uri)"
833 Make an HTTP request over the specified connection\&. The connection gets ownership of the request\&. On failure, the request object is no longer valid as it has been freed\&.
837 \fIevcon\fP the evhttp_connection object over which to send the request
839 \fIreq\fP the previously created and configured request object
841 \fItype\fP the request type EVHTTP_REQ_GET, EVHTTP_REQ_POST, etc\&.
843 \fIuri\fP the URI associated with the request
848 0 on success, -1 on failure
853 \fBevhttp_cancel_request()\fP
857 .SS "struct evhttp* evhttp_new (struct \fBevent_base\fP *base)"
860 Create a new HTTP server\&.
864 \fIbase\fP (optional) the event base to receive the HTTP events
869 a pointer to a newly initialized evhttp server structure
878 .SS "int evhttp_parse_query (const char *uri, struct evkeyvalq *headers)"
881 Helper function to parse out arguments in a query\&. Parsing a URI like
883 http://foo.com/?q=test&s=some+thing
885 will result in two entries in the key value queue\&.
887 The first entry is: key='q', value='test' The second entry is: key='s', value='some thing'
891 This function is deprecated as of Libevent 2\&.0\&.9\&. Use evhttp_uri_parse and evhttp_parse_query_str instead\&.
897 \fIuri\fP the request URI
899 \fIheaders\fP the head of the evkeyval queue
904 0 on success, -1 on failure
908 .SS "int evhttp_parse_query_str (const char *uri, struct evkeyvalq *headers)"
911 Helper function to parse out arguments from the query portion of an HTTP URI\&. Parsing a query string like
915 will result in two entries in the key value queue\&.
917 The first entry is: key='q', value='test' The second entry is: key='s', value='some thing'
921 \fIquery_parse\fP the query portion of the URI
923 \fIheaders\fP the head of the evkeyval queue
928 0 on success, -1 on failure
932 .SS "int evhttp_remove_header (struct evkeyvalq *headers, const char *key)"
935 Removes a header from a list of existing headers\&.
939 \fIheaders\fP the evkeyvalq object from which to remove a header
941 \fIkey\fP the name of the header to remove
946 0 if the header was removed, -1 otherwise\&.
951 \fBevhttp_find_header()\fP, \fBevhttp_add_header()\fP
955 .SS "int evhttp_remove_server_alias (struct evhttp *http, const char *alias)"
958 Remove a server alias from an http object\&.
962 \fIhttp\fP the evhttp object
964 \fIalias\fP the alias to remove
969 \fBevhttp_add_server_alias()\fP
973 .SS "int evhttp_remove_virtual_host (struct evhttp *http, struct evhttp *vhost)"
976 Removes a virtual host from the http server\&.
980 \fIhttp\fP the evhttp object from which to remove the virtual host
982 \fIvhost\fP the virtual host to remove from the regular http server\&.
987 0 on success, -1 on failure
992 \fBevhttp_add_virtual_host()\fP
996 .SS "void evhttp_request_free (struct evhttp_request *req)"
999 Frees the request object and removes associated events\&.
1000 .SS "struct evhttp_connection* evhttp_request_get_connection (struct evhttp_request *req)"
1003 Returns the connection object associated with the request or NULL\&. The user needs to either free the request explicitly or call \fBevhttp_send_reply_end()\fP\&.
1004 .SS "const char* evhttp_request_get_host (struct evhttp_request *req)"
1007 Returns the host associated with the request\&. If a client sends an absolute URI, the host part of that is preferred\&. Otherwise, the input headers are searched for a Host: header\&. NULL is returned if no absolute URI or Host: header is provided\&.
1008 .SS "struct evhttp_request* evhttp_request_new (void(*)(struct evhttp_request *, void *)cb, void *arg)"
1011 Creates a new request object that needs to be filled in with the request parameters\&. The callback is executed when the request completed or an error occurred\&.
1012 .SS "void evhttp_request_own (struct evhttp_request *req)"
1015 Takes ownership of the request object\&. Can be used in a request callback to keep onto the request until \fBevhttp_request_free()\fP is explicitly called by the user\&.
1016 .SS "void evhttp_request_set_chunked_cb (struct evhttp_request *, void(*)(struct evhttp_request *, void *)cb)"
1019 Enable delivery of chunks to requestor\&.
1023 \fIcb\fP will be called after every read of data with the same argument as the completion callback\&. Will never be called on an empty response\&. May drain the input buffer; it will be drained automatically on return\&.
1027 .SS "void evhttp_send_error (struct evhttp_request *req, interror, const char *reason)"
1030 Send an HTML error message to the client\&.
1034 \fIreq\fP a request object
1036 \fIerror\fP the HTTP error code
1038 \fIreason\fP a brief explanation of the error\&. If this is NULL, we'll just use the standard meaning of the error code\&.
1042 .SS "void evhttp_send_reply (struct evhttp_request *req, intcode, const char *reason, struct \fBevbuffer\fP *databuf)"
1045 Send an HTML reply to the client\&. The body of the reply consists of the data in databuf\&. After calling \fBevhttp_send_reply()\fP databuf will be empty, but the buffer is still owned by the caller and needs to be deallocated by the caller if necessary\&.
1049 \fIreq\fP a request object
1051 \fIcode\fP the HTTP response code to send
1053 \fIreason\fP a brief message to send with the response code
1055 \fIdatabuf\fP the body of the response
1059 .SS "void evhttp_send_reply_chunk (struct evhttp_request *req, struct \fBevbuffer\fP *databuf)"
1062 Send another data chunk as part of an ongoing chunked reply\&. The reply chunk consists of the data in databuf\&. After calling \fBevhttp_send_reply_chunk()\fP databuf will be empty, but the buffer is still owned by the caller and needs to be deallocated by the caller if necessary\&.
1066 \fIreq\fP a request object
1068 \fIdatabuf\fP the data chunk to send as part of the reply\&.
1072 .SS "void evhttp_send_reply_end (struct evhttp_request *req)"
1075 Complete a chunked reply, freeing the request as appropriate\&.
1079 \fIreq\fP a request object
1083 .SS "void evhttp_send_reply_start (struct evhttp_request *req, intcode, const char *reason)"
1086 Initiate a reply that uses Transfer-Encoding chunked\&. This allows the caller to stream the reply back to the client and is useful when either not all of the reply data is immediately available or when sending very large replies\&.
1088 The caller needs to supply data chunks with \fBevhttp_send_reply_chunk()\fP and complete the reply by calling \fBevhttp_send_reply_end()\fP\&.
1092 \fIreq\fP a request object
1094 \fIcode\fP the HTTP response code to send
1096 \fIreason\fP a brief message to send with the response code
1100 .SS "void evhttp_set_allowed_methods (struct evhttp *http, ev_uint16_tmethods)"
1103 Sets the what HTTP methods are supported in requests accepted by this server, and passed to user callbacks\&. If not supported they will generate a '405 Method not allowed' response\&.
1105 By default this includes the following methods: GET, POST, HEAD, PUT, DELETE
1109 \fIhttp\fP the http server on which to set the methods
1111 \fImethods\fP bit mask constructed from evhttp_cmd_type values
1115 .SS "int evhttp_set_cb (struct evhttp *http, const char *path, void(*)(struct evhttp_request *, void *)cb, void *cb_arg)"
1118 Set a callback for a specified URI\&.
1122 \fIhttp\fP the http sever on which to set the callback
1124 \fIpath\fP the path for which to invoke the callback
1126 \fIcb\fP the callback function that gets invoked on requesting path
1128 \fIcb_arg\fP an additional context argument for the callback
1133 0 on success, -1 if the callback existed already, -2 on failure
1137 .SS "void evhttp_set_gencb (struct evhttp *http, void(*)(struct evhttp_request *, void *)cb, void *arg)"
1140 Set a callback for all requests that are not caught by specific callbacks\&. Invokes the specified callback for all requests that do not match any of the previously specified request paths\&. This is catchall for requests not specifically configured with \fBevhttp_set_cb()\fP\&.
1144 \fIhttp\fP the evhttp server object for which to set the callback
1146 \fIcb\fP the callback to invoke for any unmatched requests
1148 \fIarg\fP an context argument for the callback
1152 .SS "void evhttp_set_max_body_size (struct evhttp *http, ev_ssize_tmax_body_size)"
1156 .SS "void evhttp_set_max_headers_size (struct evhttp *http, ev_ssize_tmax_headers_size)"
1160 .SS "void evhttp_set_timeout (struct evhttp *http, inttimeout_in_secs)"
1163 Set the timeout for an HTTP request\&.
1167 \fIhttp\fP an evhttp object
1169 \fItimeout_in_secs\fP the timeout, in seconds
1173 .SS "void evhttp_uri_free (struct evhttp_uri *uri)"
1176 Free all memory allocated for a parsed uri\&. Only use this for URIs generated by evhttp_uri_parse\&.
1180 \fIuri\fP container with parsed data
1185 \fBevhttp_uri_parse()\fP
1189 .SS "const char* evhttp_uri_get_host (const struct evhttp_uri *uri)"
1192 Return the host part of an evhttp_uri, or NULL if it has no host set\&. The host may either be a regular hostname (conforming to the RFC 3986 'regname' production), or an IPv4 address, or the empty string, or a bracketed IPv6 address, or a bracketed 'IP-Future' address\&.
1194 Note that having a NULL host means that the URI has no authority section, but having an empty-string host means that the URI has an authority section with no host part\&. For example, 'mailto:user@example\&.com' has a host of NULL, but 'file:///etc/motd' has a host of ''\&.
1195 .SS "int evhttp_uri_get_port (const struct evhttp_uri *uri)"
1198 Return the port part of an evhttp_uri, or -1 if there is no port set\&.
1199 .SS "const char* evhttp_uri_get_scheme (const struct evhttp_uri *uri)"
1202 Return the scheme of an evhttp_uri, or NULL if there is no scheme has been set and the evhttp_uri contains a Relative-Ref\&.
1203 .SS "char* evhttp_uri_join (struct evhttp_uri *uri, char *buf, size_tlimit)"
1206 Join together the uri parts from parsed data to form a URI-Reference\&. Note that no escaping of reserved characters is done on the members of the evhttp_uri, so the generated string might not be a valid URI unless the members of evhttp_uri are themselves valid\&.
1210 \fIuri\fP container with parsed data
1212 \fIbuf\fP destination buffer
1214 \fIlimit\fP destination buffer size
1219 an joined uri as string or NULL on error
1224 \fBevhttp_uri_parse()\fP
1228 .SS "struct evhttp_uri* evhttp_uri_parse_with_flags (const char *source_uri, unsignedflags)"
1231 Helper function to parse a URI-Reference as specified by RFC3986\&. This function matches the URI-Reference production from RFC3986, which includes both URIs like
1233 scheme://[[userinfo]@]foo\&.com[:port]]/[path][?query][#fragment]
1235 and relative-refs like
1237 [path][?query][#fragment]
1239 Any optional elements portions not present in the original URI are left set to NULL in the resulting evhttp_uri\&. If no port is specified, the port is set to -1\&.
1241 Note that no decoding is performed on percent-escaped characters in the string; if you want to parse them, use evhttp_uridecode or evhttp_parse_query_str as appropriate\&.
1243 Note also that most URI schemes will have additional constraints that this function does not know about, and cannot check\&. For example, mailto://www\&.example\&.com/cgi-bin/fortune\&.pl is not a reasonable mailto url, http://www.example.com:99999/ is not a reasonable HTTP URL, and ftp:username@example.com is not a reasonable FTP URL\&. Nevertheless, all of these URLs conform to RFC3986, and this function accepts all of them as valid\&.
1247 \fIsource_uri\fP the request URI
1249 \fIflags\fP Zero or more EVHTTP_URI_* flags to affect the behavior of the parser\&.
1254 uri container to hold parsed data, or NULL if there is error
1259 \fBevhttp_uri_free()\fP
1263 .SS "void evhttp_uri_set_flags (struct evhttp_uri *uri, unsignedflags)"
1266 Changes the flags set on a given URI\&. See EVHTTP_URI_* for a list of flags\&.
1267 .SS "int evhttp_uri_set_fragment (struct evhttp_uri *uri, const char *fragment)"
1270 Set the fragment of an evhttp_uri, or clear the fragment if fragment==NULL\&. The fragment should not include a leading '#'\&. Returns 0 on success, -1 if fragment is not well-formed\&.
1271 .SS "int evhttp_uri_set_host (struct evhttp_uri *uri, const char *host)"
1274 Set the host of an evhttp_uri, or clear the host if host==NULL\&. Returns 0 on success, -1 if host is not well-formed\&.
1275 .SS "int evhttp_uri_set_path (struct evhttp_uri *uri, const char *path)"
1278 Set the path of an evhttp_uri, or clear the path if path==NULL\&. Returns 0 on success, -1 if path is not well-formed\&.
1279 .SS "int evhttp_uri_set_port (struct evhttp_uri *uri, intport)"
1282 Set the port of an evhttp_uri, or clear the port if port==-1\&. Returns 0 on success, -1 if port is not well-formed\&.
1283 .SS "int evhttp_uri_set_query (struct evhttp_uri *uri, const char *query)"
1286 Set the query of an evhttp_uri, or clear the query if query==NULL\&. The query should not include a leading '?'\&. Returns 0 on success, -1 if query is not well-formed\&.
1287 .SS "int evhttp_uri_set_scheme (struct evhttp_uri *uri, const char *scheme)"
1290 Set the scheme of an evhttp_uri, or clear the scheme if scheme==NULL\&. Returns 0 on success, -1 if scheme is not well-formed\&.
1291 .SS "int evhttp_uri_set_userinfo (struct evhttp_uri *uri, const char *userinfo)"
1294 Set the userinfo of an evhttp_uri, or clear the userinfo if userinfo==NULL\&. Returns 0 on success, -1 if userinfo is not well-formed\&.
1295 .SS "char* evhttp_uridecode (const char *uri, intdecode_plus, size_t *size_out)"
1298 Helper function to decode a URI-escaped string or HTTP parameter\&. If 'decode_plus' is 1, then we decode the string as an HTTP parameter value, and convert all plus ('+') characters to spaces\&. If 'decode_plus' is 0, we leave all plus characters unchanged\&.
1300 The returned string must be freed by the caller\&.
1304 \fIuri\fP a URI-encode encoded URI
1306 \fIdecode_plus\fP determines whether we convert '+' to sapce\&.
1308 \fIsize_out\fP if size_out is not NULL, *size_out is set to the size of the returned string
1313 a newly allocated unencoded URI or NULL on failure
1317 .SS "char* evhttp_uriencode (const char *str, ev_ssize_tsize, intspace_to_plus)"
1320 As evhttp_encode_uri, but if 'size' is nonnegative, treat the string as being 'size' bytes long\&. This allows you to encode strings that may contain 0-valued bytes\&.
1322 The returned string must be freed by the caller\&.
1326 \fIstr\fP an unencoded string
1328 \fIsize\fP the length of the string to encode, or -1 if the string is NUL-terminated
1330 \fIspace_to_plus\fP if true, space characters in 'str' are encoded as +, not %20\&.
1335 a newly allocate URI-encoded string, or NULL on failure\&.
1341 Generated automatically by Doxygen for libevent from the source code\&.