Manual browser: evhttp(3)
evhttp(3) | Library Functions Manual | evhttp(3) |
NAME
evhttp -Basic support for HTTP serving.
SYNOPSIS
#include <event2/http.h>Macros
#define EVHTTP_URI_NONCONFORMANT 0x01
Enumerations
enum evhttp_cmd_type { EVHTTP_REQ_GET = 1 << 0, EVHTTP_REQ_POST = 1 << 1, EVHTTP_REQ_HEAD = 1 << 2, EVHTTP_REQ_PUT = 1 << 3, EVHTTP_REQ_DELETE = 1 << 4, EVHTTP_REQ_OPTIONS = 1 << 5, EVHTTP_REQ_TRACE = 1 << 6, EVHTTP_REQ_CONNECT = 1 << 7, EVHTTP_REQ_PATCH = 1 << 8 }
Functions
int evhttp_accept_socket (struct evhttp *http, evutil_socket_t fd)
Detailed Description
Basic support for HTTP serving.Macro Definition Documentation
#define EVHTTP_URI_NONCONFORMANT 0x01
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.Currently, these changes are:
- •
- Nonconformant URIs are allowed to contain otherwise unreasonable characters in their path, query, and fragment components.
Enumeration Type Documentation
enum evhttp_cmd_type
The different request types supported by evhttp. These are as specified in RFC2616, except for PATCH which is specified by RFC5789.By default, only some of these methods are accepted and passed to user callbacks; use evhttp_set_allowed_methods() to change which methods are allowed.
Function Documentation
int evhttp_accept_socket (struct evhttp *http, evutil_socket_tfd)
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.Can be called multiple times to have the http server listen to multiple different sockets.
Parameters:
Returns:
See Also:
struct evhttp_bound_socket* evhttp_accept_socket_with_handle (struct evhttp *http, evutil_socket_tfd) [read]
Like evhttp_accept_socket(), but returns a handle for referencing the socket. The returned pointer is not valid after http is freed.Parameters:
Returns:
See Also:
int evhttp_add_header (struct evkeyvalq *headers, const char *key, const char *value)
Adds a header to a list of existing headers. Parameters:Returns:
See Also:
int evhttp_add_server_alias (struct evhttp *http, const char *alias)
Add a server alias to an http object. The http object can be a virtual host or the main server.Parameters:
See Also:
int evhttp_add_virtual_host (struct evhttp *http, const char *pattern, struct evhttp *vhost)
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 evhttp_set_cb() or evhttp_set_gencb(). It most not have any listing sockets associated with it.If the virtual host has not been removed by the time that evhttp_free() is called on the main http server, it will be automatically freed, too.
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.
Parameters:
Returns:
See Also:
struct evhttp_bound_socket* evhttp_bind_listener (struct evhttp *http, struct evconnlistener *listener) [read]
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.int evhttp_bind_socket (struct evhttp *http, const char *address, ev_uint16_tport)
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.Parameters:
Returns:
See Also:
struct evhttp_bound_socket* evhttp_bind_socket_with_handle (struct evhttp *http, const char *address, ev_uint16_tport) [read]
Like evhttp_bind_socket(), but returns a handle for referencing the socket. The returned pointer is not valid after http is freed.Parameters:
Returns:
See Also:
evutil_socket_t evhttp_bound_socket_get_fd (struct evhttp_bound_socket *bound_socket)
Get the raw file descriptor referenced by an evhttp_bound_socket. Parameters:Returns:
See Also:
void evhttp_cancel_request (struct evhttp_request *req)
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.A request cannot be canceled if its callback has executed already. A request may be canceled reentrantly from its chunked callback.
Parameters:
void evhttp_clear_headers (struct evkeyvalq *headers)
Removes all headers from the header list. Parameters:
struct evhttp_connection* evhttp_connection_base_new (struct event_base *base, struct evdns_base *dnsbase, const char *address, unsigned shortport) [read]
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.Parameters:
Returns:
void evhttp_connection_get_peer (struct evhttp_connection *evcon, char **address, ev_uint16_t *port)
Get the remote address and port associated with this connection.void evhttp_connection_set_closecb (struct evhttp_connection *evcon, void(*)(struct evhttp_connection *, void *), void *)
Set a callback for connection close.char* evhttp_decode_uri (const char *uri)
Helper function to sort of decode a URI-encoded string. Unlike evhttp_get_decoded_uri, it decodes all plus characters that appear after 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.The returned string must be freed by the caller
Deprecated
Parameters:
Returns:
void evhttp_del_accept_socket (struct evhttp *http, struct evhttp_bound_socket *bound_socket)
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.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.
bound_socket is an invalid pointer after this call returns.
Parameters:
See Also:
char* evhttp_encode_uri (const char *str)
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.The returned string must be freed by the caller.
Parameters:
Returns:
const char* evhttp_find_header (const struct evkeyvalq *headers, const char *key)
Finds the value belonging to a header. Parameters:Returns:
See Also:
void evhttp_free (struct evhttp *http)
Free the previously created HTTP server. Works only if no requests are currently being served.Parameters:
See Also:
char* evhttp_htmlescape (const char *html)
Escape HTML character entities in a string. Replaces <, >, ", ' and & with <, >, ", ' and & correspondingly.The returned string needs to be freed by the caller.
Parameters:
Returns:
int evhttp_make_request (struct evhttp_connection *evcon, struct evhttp_request *req, enum evhttp_cmd_typetype, const char *uri)
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.Parameters:
Returns:
See Also:
struct evhttp* evhttp_new (struct event_base *base) [read]
Create a new HTTP server. Parameters:Returns:
See Also:
int evhttp_parse_query (const char *uri, struct evkeyvalq *headers)
Helper function to parse out arguments in a query. Parsing a URI likehttp://foo.com/?q=test&s=some+thing
will result in two entries in the key value queue.
The first entry is: key='q', value='test' The second entry is: key='s', value='some thing'
Deprecated
Parameters:
Returns:
int evhttp_parse_query_str (const char *uri, struct evkeyvalq *headers)
Helper function to parse out arguments from the query portion of an HTTP URI. Parsing a query string likeq=test&s=some+thing
will result in two entries in the key value queue.
The first entry is: key='q', value='test' The second entry is: key='s', value='some thing'
Parameters:
Returns:
int evhttp_remove_header (struct evkeyvalq *headers, const char *key)
Removes a header from a list of existing headers. Parameters:Returns:
See Also:
int evhttp_remove_server_alias (struct evhttp *http, const char *alias)
Remove a server alias from an http object. Parameters:See Also:
int evhttp_remove_virtual_host (struct evhttp *http, struct evhttp *vhost)
Removes a virtual host from the http server. Parameters:Returns:
See Also:
void evhttp_request_free (struct evhttp_request *req)
Frees the request object and removes associated events.struct evhttp_connection* evhttp_request_get_connection (struct evhttp_request *req) [read]
Returns the connection object associated with the request or NULL. The user needs to either free the request explicitly or call evhttp_send_reply_end().const char* evhttp_request_get_host (struct evhttp_request *req)
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.struct evhttp_request* evhttp_request_new (void(*)(struct evhttp_request *, void *)cb, void *arg) [read]
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.void evhttp_request_own (struct evhttp_request *req)
Takes ownership of the request object. Can be used in a request callback to keep onto the request until evhttp_request_free() is explicitly called by the user.void evhttp_request_set_chunked_cb (struct evhttp_request *, void(*)(struct evhttp_request *, void *)cb)
Enable delivery of chunks to requestor. Parameters:
void evhttp_send_error (struct evhttp_request *req, interror, const char *reason)
Send an HTML error message to the client. Parameters:
void evhttp_send_reply (struct evhttp_request *req, intcode, const char *reason, struct evbuffer *databuf)
Send an HTML reply to the client. The body of the reply consists of the data in databuf. After calling evhttp_send_reply() databuf will be empty, but the buffer is still owned by the caller and needs to be deallocated by the caller if necessary.Parameters:
void evhttp_send_reply_chunk (struct evhttp_request *req, struct evbuffer *databuf)
Send another data chunk as part of an ongoing chunked reply. The reply chunk consists of the data in databuf. After calling evhttp_send_reply_chunk() databuf will be empty, but the buffer is still owned by the caller and needs to be deallocated by the caller if necessary.Parameters:
void evhttp_send_reply_end (struct evhttp_request *req)
Complete a chunked reply, freeing the request as appropriate. Parameters:
void evhttp_send_reply_start (struct evhttp_request *req, intcode, const char *reason)
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.The caller needs to supply data chunks with evhttp_send_reply_chunk() and complete the reply by calling evhttp_send_reply_end().
Parameters:
void evhttp_set_allowed_methods (struct evhttp *http, ev_uint16_tmethods)
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.By default this includes the following methods: GET, POST, HEAD, PUT, DELETE
Parameters:
int evhttp_set_cb (struct evhttp *http, const char *path, void(*)(struct evhttp_request *, void *)cb, void *cb_arg)
Set a callback for a specified URI. Parameters:Returns:
void evhttp_set_gencb (struct evhttp *http, void(*)(struct evhttp_request *, void *)cb, void *arg)
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 evhttp_set_cb().Parameters:
void evhttp_set_max_body_size (struct evhttp *http, ev_ssize_tmax_body_size)
XXX Document.void evhttp_set_max_headers_size (struct evhttp *http, ev_ssize_tmax_headers_size)
XXX Document.void evhttp_set_timeout (struct evhttp *http, inttimeout_in_secs)
Set the timeout for an HTTP request. Parameters:
void evhttp_uri_free (struct evhttp_uri *uri)
Free all memory allocated for a parsed uri. Only use this for URIs generated by evhttp_uri_parse.Parameters:
See Also:
const char* evhttp_uri_get_host (const struct evhttp_uri *uri)
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.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 ''.
int evhttp_uri_get_port (const struct evhttp_uri *uri)
Return the port part of an evhttp_uri, or -1 if there is no port set.const char* evhttp_uri_get_scheme (const struct evhttp_uri *uri)
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.char* evhttp_uri_join (struct evhttp_uri *uri, char *buf, size_tlimit)
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.Parameters:
Returns:
See Also:
struct evhttp_uri* evhttp_uri_parse_with_flags (const char *source_uri, unsignedflags) [read]
Helper function to parse a URI-Reference as specified by RFC3986. This function matches the URI-Reference production from RFC3986, which includes both URIs likescheme://[[userinfo]@]foo.com[:port]]/[path][?query][#fragment]
and relative-refs like
[path][?query][#fragment]
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.
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.
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.
Parameters:
Returns:
See Also:
void evhttp_uri_set_flags (struct evhttp_uri *uri, unsignedflags)
Changes the flags set on a given URI. See EVHTTP_URI_* for a list of flags.int evhttp_uri_set_fragment (struct evhttp_uri *uri, const char *fragment)
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.int evhttp_uri_set_host (struct evhttp_uri *uri, const char *host)
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.int evhttp_uri_set_path (struct evhttp_uri *uri, const char *path)
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.int evhttp_uri_set_port (struct evhttp_uri *uri, intport)
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.int evhttp_uri_set_query (struct evhttp_uri *uri, const char *query)
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.int evhttp_uri_set_scheme (struct evhttp_uri *uri, const char *scheme)
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.int evhttp_uri_set_userinfo (struct evhttp_uri *uri, const char *userinfo)
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.char* evhttp_uridecode (const char *uri, intdecode_plus, size_t *size_out)
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.The returned string must be freed by the caller.
Parameters:
Returns:
char* evhttp_uriencode (const char *str, ev_ssize_tsize, intspace_to_plus)
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.The returned string must be freed by the caller.
Parameters:
Returns:
Author
Generated automatically by Doxygen for libevent from the source code.Wed Apr 10 2013 | libevent |