libevent  2.2.1
Event notification library
Data Structures | Macros | Typedefs | Enumerations | Functions
http.h File Reference

Basic support for HTTP serving. More...

#include <event2/util.h>
#include <event2/visibility.h>

Go to the source code of this file.

Data Structures

struct  evhttp_ext_method
 stucture that is passed to (and modified by) the extended method callback function More...
 

Macros

#define EVHTTP_CON_LINGERING_CLOSE   0x0020
 
#define EVHTTP_CON_PUBLIC_FLAGS_END   0x100000
 
#define EVHTTP_CON_READ_ON_WRITE_ERROR   0x0010
 
#define EVHTTP_CON_REUSE_CONNECTED_ADDR   0x0008
 
#define EVHTTP_METHOD_HAS_BODY   0x0001
 
#define EVHTTP_REQ_MAX   EVHTTP_REQ_MOVE
 
#define EVHTTP_SERVER_LINGERING_CLOSE   0x0001
 
#define EVHTTP_URI_HOST_STRIP_BRACKETS   0x04
 Strip brackets from the IPv6 address and only for evhttp_uri_get_host(), evhttp_uri_join() returns the host with brackets. More...
 
#define EVHTTP_URI_NONCONFORMANT   0x01
 Tolerate URIs that do not conform to RFC3986. More...
 
#define EVHTTP_URI_QUERY_LAST_VAL   0x02
 Prefer last value over the first from query args. More...
 
#define EVHTTP_URI_QUERY_NONCONFORMANT   0x01
 Tolerate queries that are not standard conformant. More...
 
#define EVHTTP_URI_UNIX_SOCKET   0x08
 Parse unix domain socket URIs, for example: More...
 
#define HTTP_ACCEPTED   202
 accepted for processing
 
#define HTTP_BADGATEWAY   502
 received an invalid response from the upstream
 
#define HTTP_BADMETHOD   405
 method not allowed for this uri
 
#define HTTP_BADREQUEST   400
 invalid http request was made
 
#define HTTP_CONTINUE   100
 client should proceed to send
 
#define HTTP_CREATED   201
 new resource is created
 
#define HTTP_EARLYHINTS   103
 return some response headers
 
#define HTTP_ENTITYTOOLARGE   413
 request is larger than the server is able to process
 
#define HTTP_EXPECTATIONFAILED   417
 we can't handle this expectation
 
#define HTTP_FORBIDDEN   403
 user not having the necessary permissions
 
#define HTTP_INTERNAL   500
 internal error
 
#define HTTP_MOVEPERM   301
 the uri moved permanently
 
#define HTTP_MOVETEMP   302
 the uri moved temporarily
 
#define HTTP_NOCONTENT   204
 request does not have content
 
#define HTTP_NONAUTHORITATIVE   203
 returning a modified version of the origin's response
 
#define HTTP_NOTFOUND   404
 could not find content for uri
 
#define HTTP_NOTIMPLEMENTED   501
 not implemented
 
#define HTTP_NOTMODIFIED   304
 page was not modified from last
 
#define HTTP_OK   200
 request completed ok
 
#define HTTP_PAYMENTREQUIRED   402
 user exceeded limit on requests
 
#define HTTP_PROCESSING   102
 processing the request, but no response is available yet
 
#define HTTP_SERVUNAVAIL   503
 the server is not available
 
#define HTTP_SWITCH_PROTOCOLS   101
 switching to another protocol
 
#define HTTP_UNAUTHORIZED   401
 authentication is required
 

Typedefs

typedef void evhttp_bound_socket_foreach_fn(struct evhttp_bound_socket *, void *)
 
typedef int(* evhttp_ext_method_cb) (struct evhttp_ext_method *)
 

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, EVHTTP_REQ_PROPFIND = 1 << 9, EVHTTP_REQ_PROPPATCH =1 << 10, EVHTTP_REQ_MKCOL = 1 << 11,
  EVHTTP_REQ_LOCK = 1 << 12, EVHTTP_REQ_UNLOCK = 1 << 13, EVHTTP_REQ_COPY = 1 << 14, EVHTTP_REQ_MOVE = 1 << 15
}
 The different request types supported by evhttp. More...
 
enum  evhttp_request_error {
  EVREQ_HTTP_TIMEOUT, EVREQ_HTTP_EOF, EVREQ_HTTP_INVALID_HEADER, EVREQ_HTTP_BUFFER_ERROR,
  EVREQ_HTTP_REQUEST_CANCEL, EVREQ_HTTP_DATA_TOO_LONG
}
 The different error types supported by evhttp. More...
 
enum  evhttp_request_kind { EVHTTP_REQUEST, EVHTTP_RESPONSE }
 a request object can represent either a request or a reply
 

Functions

EVENT2_EXPORT_SYMBOL int evhttp_accept_socket (struct evhttp *http, evutil_socket_t fd)
 Makes an HTTP server accept connections on the specified socket. More...
 
EVENT2_EXPORT_SYMBOL struct evhttp_bound_socket * evhttp_accept_socket_with_handle (struct evhttp *http, evutil_socket_t fd)
 Like evhttp_accept_socket(), but returns a handle for referencing the socket. More...
 
EVENT2_EXPORT_SYMBOL int evhttp_add_header (struct evkeyvalq *headers, const char *key, const char *value)
 Adds a header to a list of existing headers. More...
 
EVENT2_EXPORT_SYMBOL int evhttp_add_server_alias (struct evhttp *http, const char *alias)
 Add a server alias to an http object. More...
 
EVENT2_EXPORT_SYMBOL int evhttp_add_virtual_host (struct evhttp *http, const char *pattern, struct evhttp *vhost)
 Adds a virtual host to the http server. More...
 
EVENT2_EXPORT_SYMBOL struct evhttp_bound_socket * evhttp_bind_listener (struct evhttp *http, struct evconnlistener *listener)
 The most low-level evhttp_bind/accept method: takes an evconnlistener, and returns an evhttp_bound_socket. More...
 
EVENT2_EXPORT_SYMBOL int evhttp_bind_socket (struct evhttp *http, const char *address, ev_uint16_t port)
 Binds an HTTP server on the specified address and port. More...
 
EVENT2_EXPORT_SYMBOL struct evhttp_bound_socket * evhttp_bind_socket_with_handle (struct evhttp *http, const char *address, ev_uint16_t port)
 Like evhttp_bind_socket(), but returns a handle for referencing the socket. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_bound_set_bevcb (struct evhttp_bound_socket *bound, struct bufferevent *(*cb)(struct event_base *, void *), void *cbarg)
 
EVENT2_EXPORT_SYMBOL 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. More...
 
EVENT2_EXPORT_SYMBOL struct evconnlistener * evhttp_bound_socket_get_listener (struct evhttp_bound_socket *bound)
 Return the listener used to implement a bound socket.
 
EVENT2_EXPORT_SYMBOL void evhttp_cancel_request (struct evhttp_request *req)
 Cancels a pending HTTP request. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_clear_headers (struct evkeyvalq *headers)
 Removes all headers from the header list. More...
 
EVENT2_EXPORT_SYMBOL struct evhttp_connection * evhttp_connection_base_bufferevent_new (struct event_base *base, struct evdns_base *dnsbase, struct bufferevent *bev, const char *address, ev_uint16_t port)
 Create and return a connection object that can be used to for making HTTP requests. More...
 
EVENT2_EXPORT_SYMBOL struct evhttp_connection * evhttp_connection_base_bufferevent_unix_new (struct event_base *base, struct bufferevent *bev, const char *path)
 Create and return a connection object that can be used to for making HTTP requests over an unix domain socket. More...
 
EVENT2_EXPORT_SYMBOL struct evhttp_connection * evhttp_connection_base_new (struct event_base *base, struct evdns_base *dnsbase, const char *address, ev_uint16_t port)
 Create and return a connection object that can be used to for making HTTP requests. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_connection_free (struct evhttp_connection *evcon)
 Frees an http connection.
 
EVENT2_EXPORT_SYMBOL void evhttp_connection_free_on_completion (struct evhttp_connection *evcon)
 Disowns a given connection object. More...
 
EVENT2_EXPORT_SYMBOL const struct sockaddr * evhttp_connection_get_addr (struct evhttp_connection *evcon)
 Get the remote address associated with this connection. More...
 
EVENT2_EXPORT_SYMBOL struct event_baseevhttp_connection_get_base (struct evhttp_connection *req)
 Returns the underlying event_base for this connection.
 
EVENT2_EXPORT_SYMBOL struct buffereventevhttp_connection_get_bufferevent (struct evhttp_connection *evcon)
 Return the bufferevent that an evhttp_connection is using.
 
EVENT2_EXPORT_SYMBOL void evhttp_connection_get_peer (struct evhttp_connection *evcon, const char **address, ev_uint16_t *port)
 Get the remote address and port associated with this connection.
 
EVENT2_EXPORT_SYMBOL struct evhttp * evhttp_connection_get_server (struct evhttp_connection *evcon)
 Return the HTTP server associated with this connection, or NULL.
 
EVENT2_EXPORT_SYMBOL void evhttp_connection_set_closecb (struct evhttp_connection *evcon, void(*)(struct evhttp_connection *, void *), void *)
 Set a callback for connection close.
 
EVENT2_EXPORT_SYMBOL void evhttp_connection_set_connect_timeout_tv (struct evhttp_connection *evcon, const struct timeval *tv)
 Sets the connect timeout for this connection. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_connection_set_ext_method_cmp (struct evhttp_connection *evcon, evhttp_ext_method_cb cmp)
 Sets extended method cmp callback for this http connection. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_connection_set_family (struct evhttp_connection *evcon, int family)
 Set family hint for DNS requests.
 
EVENT2_EXPORT_SYMBOL int evhttp_connection_set_flags (struct evhttp_connection *evcon, int flags)
 Set connection flags. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_connection_set_initial_retry_tv (struct evhttp_connection *evcon, const struct timeval *tv)
 Sets the delay before retrying requests on this connection. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_connection_set_local_address (struct evhttp_connection *evcon, const char *address)
 Sets the IP address from which http connections are made. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_connection_set_local_port (struct evhttp_connection *evcon, ev_uint16_t port)
 sets the local port from which http connections are made
 
EVENT2_EXPORT_SYMBOL void evhttp_connection_set_max_body_size (struct evhttp_connection *evcon, ev_ssize_t new_max_body_size)
 
EVENT2_EXPORT_SYMBOL void evhttp_connection_set_max_headers_size (struct evhttp_connection *evcon, ev_ssize_t new_max_headers_size)
 
EVENT2_EXPORT_SYMBOL void evhttp_connection_set_read_timeout_tv (struct evhttp_connection *evcon, const struct timeval *tv)
 Sets the read timeout for this connection. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_connection_set_retries (struct evhttp_connection *evcon, int retry_max)
 Sets the retry limit for this connection - -1 repeats indefinitely.
 
EVENT2_EXPORT_SYMBOL void evhttp_connection_set_timeout (struct evhttp_connection *evcon, int timeout)
 Sets the timeout for this connection. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_connection_set_timeout_tv (struct evhttp_connection *evcon, const struct timeval *tv)
 Sets the timeout for this connection for the following events: More...
 
EVENT2_EXPORT_SYMBOL void evhttp_connection_set_write_timeout_tv (struct evhttp_connection *evcon, const struct timeval *tv)
 Sets the write timeout for this connection. More...
 
EVENT2_EXPORT_SYMBOL char * evhttp_decode_uri (const char *uri)
 Helper function to sort of decode a URI-encoded string. More...
 
EVENT2_EXPORT_SYMBOL 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. More...
 
EVENT2_EXPORT_SYMBOL int evhttp_del_cb (struct evhttp *, const char *)
 Removes the callback for a specified URI.
 
EVENT2_EXPORT_SYMBOL char * evhttp_encode_uri (const char *str)
 Helper function to encode a string for inclusion in a URI. More...
 
const EVENT2_EXPORT_SYMBOL char * evhttp_find_header (const struct evkeyvalq *headers, const char *key)
 Finds the value belonging to a header. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_foreach_bound_socket (struct evhttp *http, evhttp_bound_socket_foreach_fn *function, void *argument)
 Applies the function specified in the first argument to all evhttp_bound_sockets associated with "http". More...
 
EVENT2_EXPORT_SYMBOL void evhttp_free (struct evhttp *http)
 Free the previously created HTTP server. More...
 
EVENT2_EXPORT_SYMBOL int evhttp_get_connection_count (struct evhttp *http)
 Get the current number of connections. More...
 
EVENT2_EXPORT_SYMBOL char * evhttp_htmlescape (const char *html)
 Escape HTML character entities in a string. More...
 
EVENT2_EXPORT_SYMBOL int evhttp_make_request (struct evhttp_connection *evcon, struct evhttp_request *req, enum evhttp_cmd_type type, const char *uri)
 Make an HTTP request over the specified connection. More...
 
EVENT2_EXPORT_SYMBOL struct evhttp * evhttp_new (struct event_base *base)
 Create a new HTTP server. More...
 
EVENT2_EXPORT_SYMBOL int evhttp_parse_query (const char *uri, struct evkeyvalq *headers)
 Helper function to parse out arguments in a query. More...
 
EVENT2_EXPORT_SYMBOL int evhttp_parse_query_str (const char *uri, struct evkeyvalq *headers)
 
EVENT2_EXPORT_SYMBOL int evhttp_parse_query_str_flags (const char *uri, struct evkeyvalq *headers, unsigned flags)
 Helper function to parse out arguments from the query portion of an HTTP URI. More...
 
EVENT2_EXPORT_SYMBOL int evhttp_remove_header (struct evkeyvalq *headers, const char *key)
 Removes a header from a list of existing headers. More...
 
EVENT2_EXPORT_SYMBOL int evhttp_remove_server_alias (struct evhttp *http, const char *alias)
 Remove a server alias from an http object. More...
 
EVENT2_EXPORT_SYMBOL int evhttp_remove_virtual_host (struct evhttp *http, struct evhttp *vhost)
 Removes a virtual host from the http server. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_request_free (struct evhttp_request *req)
 Frees the request object and removes associated events.
 
EVENT2_EXPORT_SYMBOL enum evhttp_cmd_type evhttp_request_get_command (const struct evhttp_request *req)
 Returns the request command.
 
EVENT2_EXPORT_SYMBOL struct evhttp_connection * evhttp_request_get_connection (struct evhttp_request *req)
 Returns the connection object associated with the request or NULL. More...
 
EVENT2_EXPORT_SYMBOL const struct evhttp_uri * evhttp_request_get_evhttp_uri (const struct evhttp_request *req)
 Returns the request URI (parsed)
 
const EVENT2_EXPORT_SYMBOL char * evhttp_request_get_host (struct evhttp_request *req)
 Returns the host associated with the request. More...
 
EVENT2_EXPORT_SYMBOL struct evbufferevhttp_request_get_input_buffer (struct evhttp_request *req)
 Returns the input buffer.
 
EVENT2_EXPORT_SYMBOL struct evkeyvalq * evhttp_request_get_input_headers (struct evhttp_request *req)
 Returns the input headers.
 
EVENT2_EXPORT_SYMBOL struct evbufferevhttp_request_get_output_buffer (struct evhttp_request *req)
 Returns the output buffer.
 
EVENT2_EXPORT_SYMBOL struct evkeyvalq * evhttp_request_get_output_headers (struct evhttp_request *req)
 Returns the output headers.
 
EVENT2_EXPORT_SYMBOL int evhttp_request_get_response_code (const struct evhttp_request *req)
 
const EVENT2_EXPORT_SYMBOL char * evhttp_request_get_response_code_line (const struct evhttp_request *req)
 
const EVENT2_EXPORT_SYMBOL char * evhttp_request_get_uri (const struct evhttp_request *req)
 Returns the request URI.
 
EVENT2_EXPORT_SYMBOL int evhttp_request_is_owned (struct evhttp_request *req)
 Returns 1 if the request is owned by the user.
 
EVENT2_EXPORT_SYMBOL struct evhttp_request * evhttp_request_new (void(*cb)(struct evhttp_request *, void *), void *arg)
 Creates a new request object that needs to be filled in with the request parameters. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_request_own (struct evhttp_request *req)
 Takes ownership of the request object. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_request_set_chunked_cb (struct evhttp_request *, void(*cb)(struct evhttp_request *, void *))
 Enable delivery of chunks to requestor. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_request_set_error_cb (struct evhttp_request *, void(*)(enum evhttp_request_error, void *))
 Set a callback for errors. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_request_set_header_cb (struct evhttp_request *, int(*cb)(struct evhttp_request *, void *))
 Register callback for additional parsing of request headers. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_request_set_on_complete_cb (struct evhttp_request *req, void(*cb)(struct evhttp_request *, void *), void *cb_arg)
 Set a callback to be called on request completion of evhttp_send_* function. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_send_error (struct evhttp_request *req, int error, const char *reason)
 Send an HTML error message to the client. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_send_reply (struct evhttp_request *req, int code, const char *reason, struct evbuffer *databuf)
 Send an HTML reply to the client. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_send_reply_chunk (struct evhttp_request *req, struct evbuffer *databuf)
 Send another data chunk as part of an ongoing chunked reply. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_send_reply_chunk_with_cb (struct evhttp_request *req, struct evbuffer *databuf, void(*cb)(struct evhttp_connection *, void *), void *arg)
 Send another data chunk as part of an ongoing chunked reply. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_send_reply_end (struct evhttp_request *req)
 Complete a chunked reply, freeing the request as appropriate. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_send_reply_start (struct evhttp_request *req, int code, const char *reason)
 Initiate a reply that uses Transfer-Encoding chunked. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_set_allowed_methods (struct evhttp *http, ev_uint32_t methods)
 Sets the what HTTP methods are supported in requests accepted by this server, and passed to user callbacks. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_set_bevcb (struct evhttp *http, struct bufferevent *(*cb)(struct event_base *, void *), void *arg)
 Set a callback used to create new bufferevents for connections to a given evhttp object. More...
 
EVENT2_EXPORT_SYMBOL int evhttp_set_cb (struct evhttp *http, const char *path, void(*cb)(struct evhttp_request *, void *), void *cb_arg)
 Set a callback for a specified URI. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_set_default_content_type (struct evhttp *http, const char *content_type)
 Set the value to use for the Content-Type header when none was provided. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_set_errorcb (struct evhttp *http, int(*cb)(struct evhttp_request *req, struct evbuffer *buffer, int error, const char *reason, void *cbarg), void *cbarg)
 Set a callback to output for any error pages sent for requests of a given evhttp object. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_set_ext_method_cmp (struct evhttp *http, evhttp_ext_method_cb cmp)
 Sets the callback function which allows HTTP extended methods to be supported by this server. More...
 
EVENT2_EXPORT_SYMBOL int evhttp_set_flags (struct evhttp *http, int flags)
 Set connection flags for HTTP server. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_set_gencb (struct evhttp *http, void(*cb)(struct evhttp_request *, void *), void *arg)
 Set a callback for all requests that are not caught by specific callbacks. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_set_max_body_size (struct evhttp *http, ev_ssize_t max_body_size)
 XXX Document.
 
EVENT2_EXPORT_SYMBOL void evhttp_set_max_connections (struct evhttp *http, int max_connections)
 Set the maximum number of simultaneous connections for this server. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_set_max_headers_size (struct evhttp *http, ev_ssize_t max_headers_size)
 XXX Document.
 
EVENT2_EXPORT_SYMBOL void evhttp_set_newreqcb (struct evhttp *http, int(*cb)(struct evhttp_request *, void *), void *arg)
 Set a callback which allows the user to note or throttle incoming requests. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_set_read_timeout_tv (struct evhttp *http, const struct timeval *tv)
 Set read timeout for an HTTP request. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_set_timeout (struct evhttp *http, int timeout)
 Set the timeout for an HTTP request. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_set_timeout_tv (struct evhttp *http, const struct timeval *tv)
 Set read and write timeout for an HTTP request. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_set_write_timeout_tv (struct evhttp *http, const struct timeval *tv)
 Set write timeout for an HTTP request. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_uri_free (struct evhttp_uri *uri)
 Free all memory allocated for a parsed uri. More...
 
const EVENT2_EXPORT_SYMBOL char * evhttp_uri_get_fragment (const struct evhttp_uri *uri)
 Return the fragment part of an evhttp_uri (excluding the leading "#"), or NULL if it has no fragment set.
 
const EVENT2_EXPORT_SYMBOL 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. More...
 
const EVENT2_EXPORT_SYMBOL char * evhttp_uri_get_path (const struct evhttp_uri *uri)
 Return the path part of an evhttp_uri, or NULL if it has no path set.
 
EVENT2_EXPORT_SYMBOL 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 EVENT2_EXPORT_SYMBOL char * evhttp_uri_get_query (const struct evhttp_uri *uri)
 Return the query part of an evhttp_uri (excluding the leading "?"), or NULL if it has no query set.
 
const EVENT2_EXPORT_SYMBOL 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.
 
const EVENT2_EXPORT_SYMBOL char * evhttp_uri_get_unixsocket (const struct evhttp_uri *uri)
 Return the unix socket part of an evhttp_uri, or NULL if there is no unix socket set.
 
const EVENT2_EXPORT_SYMBOL char * evhttp_uri_get_userinfo (const struct evhttp_uri *uri)
 Return the userinfo part of an evhttp_uri, or NULL if it has no userinfo set.
 
EVENT2_EXPORT_SYMBOL char * evhttp_uri_join (struct evhttp_uri *uri, char *buf, size_t limit)
 Join together the uri parts from parsed data to form a URI-Reference. More...
 
EVENT2_EXPORT_SYMBOL struct evhttp_uri * evhttp_uri_new (void)
 Return a new empty evhttp_uri with no fields set.
 
EVENT2_EXPORT_SYMBOL struct evhttp_uri * evhttp_uri_parse (const char *source_uri)
 Alias for evhttp_uri_parse_with_flags(source_uri, 0)
 
EVENT2_EXPORT_SYMBOL struct evhttp_uri * evhttp_uri_parse_with_flags (const char *source_uri, unsigned flags)
 Helper function to parse a URI-Reference as specified by RFC3986. More...
 
EVENT2_EXPORT_SYMBOL void evhttp_uri_set_flags (struct evhttp_uri *uri, unsigned flags)
 Changes the flags set on a given URI. More...
 
EVENT2_EXPORT_SYMBOL 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. More...
 
EVENT2_EXPORT_SYMBOL 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. More...
 
EVENT2_EXPORT_SYMBOL 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. More...
 
EVENT2_EXPORT_SYMBOL int evhttp_uri_set_port (struct evhttp_uri *uri, int port)
 Set the port of an evhttp_uri, or clear the port if port==-1. More...
 
EVENT2_EXPORT_SYMBOL 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. More...
 
EVENT2_EXPORT_SYMBOL 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. More...
 
EVENT2_EXPORT_SYMBOL int evhttp_uri_set_unixsocket (struct evhttp_uri *uri, const char *unixsocket)
 Set the unix socket of an evhttp_uri, or clear the unix socket if unixsocket==NULL. More...
 
EVENT2_EXPORT_SYMBOL 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. More...
 
EVENT2_EXPORT_SYMBOL char * evhttp_uridecode (const char *uri, int decode_plus, size_t *size_out)
 Helper function to decode a URI-escaped string or HTTP parameter. More...
 
EVENT2_EXPORT_SYMBOL char * evhttp_uriencode (const char *str, ev_ssize_t size, int space_to_plus)
 As evhttp_encode_uri, but if 'size' is nonnegative, treat the string as being 'size' bytes long. More...
 

Detailed Description

Basic support for HTTP serving.

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.

Macro Definition Documentation

◆ EVHTTP_URI_HOST_STRIP_BRACKETS

#define EVHTTP_URI_HOST_STRIP_BRACKETS   0x04

Strip brackets from the IPv6 address and only for evhttp_uri_get_host(), evhttp_uri_join() returns the host with brackets.

Thus you can use host part of the evhttp_uri for getaddrinfo().

See also
also _EVHTTP_URI_HOST_HAS_BRACKETS

◆ EVHTTP_URI_NONCONFORMANT

#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.

◆ EVHTTP_URI_QUERY_LAST_VAL

#define EVHTTP_URI_QUERY_LAST_VAL   0x02

Prefer last value over the first from query args.

Example: test=123&test=456 Without: test=123 With : test=456

◆ EVHTTP_URI_QUERY_NONCONFORMANT

#define EVHTTP_URI_QUERY_NONCONFORMANT   0x01

Tolerate queries that are not standard conformant.

Here are some examples:

  • test=123&test2 with with this flag test2 will be present in the output headers
  • test=123&&test2=1 will parse the query with this flag
  • test=123&=456&test2=1 will parse the queyr with this flag, however there won't be empty key present

◆ EVHTTP_URI_UNIX_SOCKET

#define EVHTTP_URI_UNIX_SOCKET   0x08

Parse unix domain socket URIs, for example:

http://unix:/run/control.sock:/controller

Enumeration Type Documentation

◆ evhttp_cmd_type

The different request types supported by evhttp.

These are as specified in RFC2616, except for:

  • PATCH which is specified by RFC5789
  • PROPFIND, PROPPATCH, MKCOL, LOCK, UNLOCK, COPY, MOVE which are specified by RFC4918

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.

◆ evhttp_request_error

The different error types supported by evhttp.

See also
evhttp_request_set_error_cb()
Enumerator
EVREQ_HTTP_TIMEOUT 

Timeout reached, also.

See also
evhttp_connection_set_timeout()
EVREQ_HTTP_EOF 

EOF reached.

EVREQ_HTTP_INVALID_HEADER 

Error while reading header, or invalid header.

EVREQ_HTTP_BUFFER_ERROR 

Error encountered while reading or writing.

EVREQ_HTTP_REQUEST_CANCEL 

The evhttp_cancel_request() called on this request.

EVREQ_HTTP_DATA_TOO_LONG 

Body is greater then evhttp_connection_set_max_body_size()

Function Documentation

◆ evhttp_accept_socket()

EVENT2_EXPORT_SYMBOL int evhttp_accept_socket ( struct evhttp *  http,
evutil_socket_t  fd 
)

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
httpa pointer to an evhttp object
fda socket fd that is ready for accepting connections
Returns
0 on success, -1 on failure.
See also
evhttp_bind_socket()

◆ evhttp_accept_socket_with_handle()

EVENT2_EXPORT_SYMBOL struct evhttp_bound_socket* evhttp_accept_socket_with_handle ( struct evhttp *  http,
evutil_socket_t  fd 
)

Like evhttp_accept_socket(), but returns a handle for referencing the socket.

The returned pointer is not valid after http is freed.

Parameters
httpa pointer to an evhttp object
fda socket fd that is ready for accepting connections
Returns
Handle for the socket on success, NULL on failure.
See also
evhttp_accept_socket(), evhttp_del_accept_socket()

◆ evhttp_add_header()

EVENT2_EXPORT_SYMBOL int evhttp_add_header ( struct evkeyvalq *  headers,
const char *  key,
const char *  value 
)

Adds a header to a list of existing headers.

Parameters
headersthe evkeyvalq object to which to add a header
keythe name of the header
valuethe value belonging to the header
Returns
0 on success, -1 otherwise.
See also
evhttp_find_header(), evhttp_clear_headers()

◆ evhttp_add_server_alias()

EVENT2_EXPORT_SYMBOL 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
httpthe evhttp object
aliasthe alias to add
See also
evhttp_add_remove_alias()

◆ evhttp_add_virtual_host()

EVENT2_EXPORT_SYMBOL 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
httpthe evhttp object to which to add a virtual host
patternthe glob pattern against which the hostname is matched. The match is case insensitive and follows otherwise regular shell matching.
vhostthe virtual host to add the regular http server.
Returns
0 on success, -1 on failure
See also
evhttp_remove_virtual_host()

◆ evhttp_bind_listener()

EVENT2_EXPORT_SYMBOL struct evhttp_bound_socket* evhttp_bind_listener ( struct evhttp *  http,
struct evconnlistener *  listener 
)

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.

◆ evhttp_bind_socket()

EVENT2_EXPORT_SYMBOL int evhttp_bind_socket ( struct evhttp *  http,
const char *  address,
ev_uint16_t  port 
)

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
httpa pointer to an evhttp object
addressa string containing the IP address to listen(2) on
portthe port number to listen on
Returns
0 on success, -1 on failure.
See also
evhttp_accept_socket()

◆ evhttp_bind_socket_with_handle()

EVENT2_EXPORT_SYMBOL struct evhttp_bound_socket* evhttp_bind_socket_with_handle ( struct evhttp *  http,
const char *  address,
ev_uint16_t  port 
)

Like evhttp_bind_socket(), but returns a handle for referencing the socket.

The returned pointer is not valid after http is freed.

Parameters
httpa pointer to an evhttp object
addressa string containing the IP address to listen(2) on
portthe port number to listen on
Returns
Handle for the socket on success, NULL on failure.
See also
evhttp_bind_socket(), evhttp_del_accept_socket()

◆ evhttp_bound_socket_get_fd()

EVENT2_EXPORT_SYMBOL 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
bound_socketa handle returned by evhttp_{bind,accept}_socket_with_handle
Returns
the file descriptor used by the bound socket
See also
evhttp_bind_socket_with_handle(), evhttp_accept_socket_with_handle()

◆ evhttp_cancel_request()

EVENT2_EXPORT_SYMBOL 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
reqthe evhttp_request to cancel; req becomes invalid after this call.

◆ evhttp_clear_headers()

EVENT2_EXPORT_SYMBOL void evhttp_clear_headers ( struct evkeyvalq *  headers)

Removes all headers from the header list.

Parameters
headersthe evkeyvalq object from which to remove all headers

◆ evhttp_connection_base_bufferevent_new()

EVENT2_EXPORT_SYMBOL struct evhttp_connection* evhttp_connection_base_bufferevent_new ( struct event_base base,
struct evdns_base *  dnsbase,
struct bufferevent bev,
const char *  address,
ev_uint16_t  port 
)

Create and return 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.

Connection also has default timeouts for the following events:

  • connect HTTP_CONNECT_TIMEOUT, which is 45 seconds
  • read HTTP_READ_TIMEOUT which is 50 seconds
  • write HTTP_WRITE_TIMEOUT, which is 50 seconds
Parameters
basethe event_base to use for handling the connection
dnsbasethe dns_base to use for resolving host names; if not specified host name resolution will block.
beva bufferevent to use for connecting to the server; if NULL, a socket-based bufferevent will be created. This bufferevent will be freed when the connection closes. It must have no fd set on it.
addressthe address to which to connect
portthe port to connect to
Returns
an evhttp_connection object that can be used for making requests or NULL on error

◆ evhttp_connection_base_bufferevent_unix_new()

EVENT2_EXPORT_SYMBOL struct evhttp_connection* evhttp_connection_base_bufferevent_unix_new ( struct event_base base,
struct bufferevent bev,
const char *  path 
)

Create and return a connection object that can be used to for making HTTP requests over an unix domain socket.

Parameters
basethe event_base to use for handling the connection
beva bufferevent to use for connecting to the server; if NULL, a socket-based bufferevent will be created. This bufferevent will be freed when the connection closes. It must have no fd set on it.
pathpath of unix domain socket
Returns
an evhttp_connection object that can be used for making requests

◆ evhttp_connection_base_new()

EVENT2_EXPORT_SYMBOL struct evhttp_connection* evhttp_connection_base_new ( struct event_base base,
struct evdns_base *  dnsbase,
const char *  address,
ev_uint16_t  port 
)

Create and return 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
basethe event_base to use for handling the connection
dnsbasethe dns_base to use for resolving host names; if not specified host name resolution will block.
addressthe address to which to connect
portthe port to connect to
Returns
an evhttp_connection object that can be used for making requests or NULL on error

◆ evhttp_connection_free_on_completion()

EVENT2_EXPORT_SYMBOL void evhttp_connection_free_on_completion ( struct evhttp_connection *  evcon)

Disowns a given connection object.

Can be used to tell libevent to free the connection object after the last request has completed or failed.

◆ evhttp_connection_get_addr()

EVENT2_EXPORT_SYMBOL const struct sockaddr* evhttp_connection_get_addr ( struct evhttp_connection *  evcon)

Get the remote address associated with this connection.

extracted from getpeername() OR from nameserver.

Returns
NULL if getpeername() return non success, or connection is not connected, otherwise it return pointer to struct sockaddr_storage

◆ evhttp_connection_set_connect_timeout_tv()

EVENT2_EXPORT_SYMBOL void evhttp_connection_set_connect_timeout_tv ( struct evhttp_connection *  evcon,
const struct timeval *  tv 
)

Sets the connect timeout for this connection.

Parameters
tvthe timeout, or NULL

◆ evhttp_connection_set_ext_method_cmp()

EVENT2_EXPORT_SYMBOL void evhttp_connection_set_ext_method_cmp ( struct evhttp_connection *  evcon,
evhttp_ext_method_cb  cmp 
)

Sets extended method cmp callback for this http connection.

See also
evhttp_set_ext_method_cmp

◆ evhttp_connection_set_flags()

EVENT2_EXPORT_SYMBOL int evhttp_connection_set_flags ( struct evhttp_connection *  evcon,
int  flags 
)

Set connection flags.

See also
EVHTTP_CON_*
Returns
0 on success, otherwise non zero (for example if flag doesn't supported).

◆ evhttp_connection_set_initial_retry_tv()

EVENT2_EXPORT_SYMBOL void evhttp_connection_set_initial_retry_tv ( struct evhttp_connection *  evcon,
const struct timeval *  tv 
)

Sets the delay before retrying requests on this connection.

This is only used if evhttp_connection_set_retries is used to make the number of retries at least one. Each retry after the first is twice as long as the one before it.

Default delay is HTTP_INITIAL_RETRY_TIMEOUT, which is 2 seconds.

◆ evhttp_connection_set_local_address()

EVENT2_EXPORT_SYMBOL void evhttp_connection_set_local_address ( struct evhttp_connection *  evcon,
const char *  address 
)

Sets the IP address from which http connections are made.

Note this resets internal bufferevent fd, so any options that had been installed will be flushed.

◆ evhttp_connection_set_read_timeout_tv()

EVENT2_EXPORT_SYMBOL void evhttp_connection_set_read_timeout_tv ( struct evhttp_connection *  evcon,
const struct timeval *  tv 
)

Sets the read timeout for this connection.

Parameters
tvthe timeout, or NULL

◆ evhttp_connection_set_timeout()

EVENT2_EXPORT_SYMBOL void evhttp_connection_set_timeout ( struct evhttp_connection *  evcon,
int  timeout 
)

Sets the timeout for this connection.

See also
evhttp_connection_set_timeout_tv()

◆ evhttp_connection_set_timeout_tv()

EVENT2_EXPORT_SYMBOL void evhttp_connection_set_timeout_tv ( struct evhttp_connection *  evcon,
const struct timeval *  tv 
)

Sets the timeout for this connection for the following events:

  • read, if tv==NULL then it uses default timeout (HTTP_READ_TIMEOUT)
  • write, if tv==NULL then it uses default timeout (HTTP_WRITE_TIMEOUT)

But it does not adjust timeout for the "connect" (for historical reasons).

Parameters
tvthe timeout, or NULL

For more precise control:

See also
evhttp_connection_set_connect_timeout_tv()
evhttp_connection_set_read_timeout_tv()
evhttp_connection_set_write_timeout_tv()

◆ evhttp_connection_set_write_timeout_tv()

EVENT2_EXPORT_SYMBOL void evhttp_connection_set_write_timeout_tv ( struct evhttp_connection *  evcon,
const struct timeval *  tv 
)

Sets the write timeout for this connection.

Parameters
tvthe timeout, or NULL

◆ evhttp_decode_uri()

EVENT2_EXPORT_SYMBOL char* evhttp_decode_uri ( const char *  uri)

Helper function to sort of decode a URI-encoded string.

Unlike evhttp_uridecode, 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:
This function is deprecated; you probably want to use evhttp_uridecode instead.
Parameters
urian encoded URI
Returns
a newly allocated unencoded URI or NULL on failure

◆ evhttp_del_accept_socket()

EVENT2_EXPORT_SYMBOL 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
httpa pointer to an evhttp object
bound_socketa handle returned by evhttp_{bind,accept}_socket_with_handle
See also
evhttp_bind_socket_with_handle(), evhttp_accept_socket_with_handle()

◆ evhttp_encode_uri()

EVENT2_EXPORT_SYMBOL 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
stran unencoded string
Returns
a newly allocated URI-encoded string or NULL on failure

◆ evhttp_find_header()

const EVENT2_EXPORT_SYMBOL char* evhttp_find_header ( const struct evkeyvalq *  headers,
const char *  key 
)

Finds the value belonging to a header.

Parameters
headersthe evkeyvalq object in which to find the header
keythe name of the header to find
Returns
a pointer to the value for the header or NULL if the header could not be found.
See also
evhttp_add_header(), evhttp_remove_header()

◆ evhttp_foreach_bound_socket()

EVENT2_EXPORT_SYMBOL void evhttp_foreach_bound_socket ( struct evhttp *  http,
evhttp_bound_socket_foreach_fn *  function,
void *  argument 
)

Applies the function specified in the first argument to all evhttp_bound_sockets associated with "http".

The user must not attempt to free or remove any connections, sockets or listeners in the callback "function".

Parameters
httppointer to an evhttp object
functionfunction to apply to every bound socket
argumentpointer value passed to function for every socket iterated

◆ evhttp_free()

EVENT2_EXPORT_SYMBOL void evhttp_free ( struct evhttp *  http)

Free the previously created HTTP server.

Works only if no requests are currently being served.

Parameters
httpthe evhttp server object to be freed
See also
evhttp_start()

◆ evhttp_get_connection_count()

EVENT2_EXPORT_SYMBOL int evhttp_get_connection_count ( struct evhttp *  http)

Get the current number of connections.

Returns
The current number of connections for this server.

◆ evhttp_htmlescape()

EVENT2_EXPORT_SYMBOL char* evhttp_htmlescape ( const char *  html)

Escape HTML character entities in a string.

Replaces <, >, ", ' and & with <, >, ", &#039; and & correspondingly.

The returned string needs to be freed by the caller.

Parameters
htmlan unescaped HTML string
Returns
an escaped HTML string or NULL on error

◆ evhttp_make_request()

EVENT2_EXPORT_SYMBOL int evhttp_make_request ( struct evhttp_connection *  evcon,
struct evhttp_request *  req,
enum evhttp_cmd_type  type,
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
evconthe evhttp_connection object over which to send the request
reqthe previously created and configured request object
typethe request type EVHTTP_REQ_GET, EVHTTP_REQ_POST, etc.
urithe URI associated with the request
Returns
0 on success, -1 on failure
See also
evhttp_cancel_request()

◆ evhttp_new()

EVENT2_EXPORT_SYMBOL struct evhttp* evhttp_new ( struct event_base base)

Create a new HTTP server.

Parameters
base(optional) the event base to receive the HTTP events
Returns
a pointer to a newly initialized evhttp server structure or NULL on error
See also
evhttp_free()

◆ evhttp_parse_query()

EVENT2_EXPORT_SYMBOL int evhttp_parse_query ( const char *  uri,
struct evkeyvalq *  headers 
)

Helper function to parse out arguments in a query.

Parsing a URI like

http://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:
This function is deprecated as of Libevent 2.0.9. Use evhttp_uri_parse and evhttp_parse_query_str instead.
Parameters
urithe request URI
headersthe head of the evkeyval queue
Returns
0 on success, -1 on failure

◆ evhttp_parse_query_str()

EVENT2_EXPORT_SYMBOL int evhttp_parse_query_str ( const char *  uri,
struct evkeyvalq *  headers 
)

◆ evhttp_parse_query_str_flags()

EVENT2_EXPORT_SYMBOL int evhttp_parse_query_str_flags ( const char *  uri,
struct evkeyvalq *  headers,
unsigned  flags 
)

Helper function to parse out arguments from the query portion of an HTTP URI.

Parsing a query string like

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"

Parameters
urithe query portion of the URI
headersthe head of the evkeyval queue
flagsone or more of EVHTTP_URI_QUERY_*
Returns
0 on success, -1 on failure

◆ evhttp_remove_header()

EVENT2_EXPORT_SYMBOL int evhttp_remove_header ( struct evkeyvalq *  headers,
const char *  key 
)

Removes a header from a list of existing headers.

Parameters
headersthe evkeyvalq object from which to remove a header
keythe name of the header to remove
Returns
0 if the header was removed, -1 otherwise.
See also
evhttp_find_header(), evhttp_add_header()

◆ evhttp_remove_server_alias()

EVENT2_EXPORT_SYMBOL int evhttp_remove_server_alias ( struct evhttp *  http,
const char *  alias 
)

Remove a server alias from an http object.

Parameters
httpthe evhttp object
aliasthe alias to remove
See also
evhttp_add_server_alias()

◆ evhttp_remove_virtual_host()

EVENT2_EXPORT_SYMBOL int evhttp_remove_virtual_host ( struct evhttp *  http,
struct evhttp *  vhost 
)

Removes a virtual host from the http server.

Parameters
httpthe evhttp object from which to remove the virtual host
vhostthe virtual host to remove from the regular http server.
Returns
0 on success, -1 on failure
See also
evhttp_add_virtual_host()

◆ evhttp_request_get_connection()

EVENT2_EXPORT_SYMBOL struct evhttp_connection* evhttp_request_get_connection ( struct evhttp_request *  req)

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().

◆ evhttp_request_get_host()

const EVENT2_EXPORT_SYMBOL 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.

◆ evhttp_request_new()

EVENT2_EXPORT_SYMBOL struct evhttp_request* evhttp_request_new ( void(*)(struct evhttp_request *, void *)  cb,
void *  arg 
)

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.

◆ evhttp_request_own()

EVENT2_EXPORT_SYMBOL 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.

◆ evhttp_request_set_chunked_cb()

EVENT2_EXPORT_SYMBOL void evhttp_request_set_chunked_cb ( struct evhttp_request *  ,
void(*)(struct evhttp_request *, void *)  cb 
)

Enable delivery of chunks to requestor.

Parameters
cbwill 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.

◆ evhttp_request_set_error_cb()

EVENT2_EXPORT_SYMBOL void evhttp_request_set_error_cb ( struct evhttp_request *  ,
void(*)(enum evhttp_request_error, void *)   
)

Set a callback for errors.

See also
evhttp_request_error for error types.

On error, both the error callback and the regular callback will be called, error callback is called before the regular callback.

◆ evhttp_request_set_header_cb()

EVENT2_EXPORT_SYMBOL void evhttp_request_set_header_cb ( struct evhttp_request *  ,
int(*)(struct evhttp_request *, void *)  cb 
)

Register callback for additional parsing of request headers.

Parameters
cbwill be called after receiving and parsing the full header. It allows analyzing the header and possibly closing the connection by returning a value < 0.

◆ evhttp_request_set_on_complete_cb()

EVENT2_EXPORT_SYMBOL void evhttp_request_set_on_complete_cb ( struct evhttp_request *  req,
void(*)(struct evhttp_request *, void *)  cb,
void *  cb_arg 
)

Set a callback to be called on request completion of evhttp_send_* function.

The callback function will be called on the completion of the request after the output data has been written and before the evhttp_request object is destroyed. This can be useful for tracking resources associated with a request (ex: timing metrics).

Parameters
reqa request object
cbcallback function that will be called on request completion
cb_argan additional context argument for the callback

◆ evhttp_send_error()

EVENT2_EXPORT_SYMBOL void evhttp_send_error ( struct evhttp_request *  req,
int  error,
const char *  reason 
)

Send an HTML error message to the client.

Parameters
reqa request object
errorthe HTTP error code
reasona brief explanation of the error. If this is NULL, we'll just use the standard meaning of the error code.

◆ evhttp_send_reply()

EVENT2_EXPORT_SYMBOL void evhttp_send_reply ( struct evhttp_request *  req,
int  code,
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
reqa request object
codethe HTTP response code to send
reasona brief message to send with the response code
databufthe body of the response

◆ evhttp_send_reply_chunk()

EVENT2_EXPORT_SYMBOL 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
reqa request object
databufthe data chunk to send as part of the reply.

◆ evhttp_send_reply_chunk_with_cb()

EVENT2_EXPORT_SYMBOL void evhttp_send_reply_chunk_with_cb ( struct evhttp_request *  req,
struct evbuffer databuf,
void(*)(struct evhttp_connection *, void *)  cb,
void *  arg 
)

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
reqa request object
databufthe data chunk to send as part of the reply.
cbcallback funcion
argcall back's argument.

◆ evhttp_send_reply_end()

EVENT2_EXPORT_SYMBOL void evhttp_send_reply_end ( struct evhttp_request *  req)

Complete a chunked reply, freeing the request as appropriate.

Parameters
reqa request object

◆ evhttp_send_reply_start()

EVENT2_EXPORT_SYMBOL void evhttp_send_reply_start ( struct evhttp_request *  req,
int  code,
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
reqa request object
codethe HTTP response code to send
reasona brief message to send with the response code

◆ evhttp_set_allowed_methods()

EVENT2_EXPORT_SYMBOL void evhttp_set_allowed_methods ( struct evhttp *  http,
ev_uint32_t  methods 
)

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
httpthe http server on which to set the methods
methodsbit mask constructed from evhttp_cmd_type values

◆ evhttp_set_bevcb()

EVENT2_EXPORT_SYMBOL void evhttp_set_bevcb ( struct evhttp *  http,
struct bufferevent *(*)(struct event_base *, void *)  cb,
void *  arg 
)

Set a callback used to create new bufferevents for connections to a given evhttp object.

cb is not called if a non-NULL bufferevent was supplied by evhttp_bound_set_bevcb.

You can use this to override the default bufferevent type – for example, to make this evhttp object use SSL bufferevents rather than unencrypted ones.

New bufferevents must be allocated with no fd set on them.

Parameters
httpthe evhttp server object for which to set the callback
cbthe callback to invoke for incoming connections
argan additional context argument for the callback

◆ evhttp_set_cb()

EVENT2_EXPORT_SYMBOL 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
httpthe http sever on which to set the callback
paththe path for which to invoke the callback
cbthe callback function that gets invoked on requesting path
cb_argan additional context argument for the callback
Returns
0 on success, -1 if the callback existed already, -2 on failure

◆ evhttp_set_default_content_type()

EVENT2_EXPORT_SYMBOL void evhttp_set_default_content_type ( struct evhttp *  http,
const char *  content_type 
)

Set the value to use for the Content-Type header when none was provided.

If the content type string is NULL, the Content-Type header will not be automatically added.

Parameters
httpthe http server on which to set the default content type
content_typethe value for the Content-Type header

◆ evhttp_set_errorcb()

EVENT2_EXPORT_SYMBOL void evhttp_set_errorcb ( struct evhttp *  http,
int(*)(struct evhttp_request *req, struct evbuffer *buffer, int error, const char *reason, void *cbarg)  cb,
void *  cbarg 
)

Set a callback to output for any error pages sent for requests of a given evhttp object.

You can use this to override the default error pages sent, allowing such things as multi-lingual support or customization to match other pages.

The callback should use the supplied buffer to output the text for an error page. If the callback returns a negative value or doesn't output anything to the buffer, the default error page will be sent instead. The buffer will be automatically be sent when the callback returns, so the callback shouldn't do so itself.

Microsoft Internet Explorer may display its own error pages if ones sent by an HTTP server are smaller than certain sizes, depending on the status code. To reliably suppress this feature an error page should be at least 512 bytes in size.

Parameters
httpthe evhttp server object for which to set the callback
cbthe callback to invoke to format error pages
argan additional context argument for the callback

◆ evhttp_set_ext_method_cmp()

EVENT2_EXPORT_SYMBOL void evhttp_set_ext_method_cmp ( struct evhttp *  http,
evhttp_ext_method_cb  cmp 
)

Sets the callback function which allows HTTP extended methods to be supported by this server.

The callback should :

  • if method field is NULL : set method field according to type field
  • else : set type and flags fields according to method string
  • return 0 for success (known method / type)
  • return -1 for error (unknown method / type)

evhttp_set_allowed_methods still needs to be called.

Parameters
httpthe http server on which to add support to the methods
cmpthe extended method callback
See also
evhttp_ext_method

◆ evhttp_set_flags()

EVENT2_EXPORT_SYMBOL int evhttp_set_flags ( struct evhttp *  http,
int  flags 
)

Set connection flags for HTTP server.

See also
EVHTTP_SERVER_*
Returns
0 on success, otherwise non zero (for example if flag doesn't supported).

◆ evhttp_set_gencb()

EVENT2_EXPORT_SYMBOL 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
httpthe evhttp server object for which to set the callback
cbthe callback to invoke for any unmatched requests
argan additional context argument for the callback

◆ evhttp_set_max_connections()

EVENT2_EXPORT_SYMBOL void evhttp_set_max_connections ( struct evhttp *  http,
int  max_connections 
)

Set the maximum number of simultaneous connections for this server.

A value of zero or less disables the limit.

Parameters
httpthe http server on which to set the max connection limit
max_connectionsthe maximum number of simultaneous connections or 0

◆ evhttp_set_newreqcb()

EVENT2_EXPORT_SYMBOL void evhttp_set_newreqcb ( struct evhttp *  http,
int(*)(struct evhttp_request *, void *)  cb,
void *  arg 
)

Set a callback which allows the user to note or throttle incoming requests.

The requests are not populated with HTTP level information. They are just associated to a connection.

If the callback returns -1, the associated connection is terminated and the request is closed.

Parameters
httpthe evhttp server object for which to set the callback
cbthe callback to invoke for incoming connections
argan additional context argument for the callback

◆ evhttp_set_read_timeout_tv()

EVENT2_EXPORT_SYMBOL void evhttp_set_read_timeout_tv ( struct evhttp *  http,
const struct timeval *  tv 
)

Set read timeout for an HTTP request.

Parameters
httpan evhttp object
tvthe timeout, or NULL

◆ evhttp_set_timeout()

EVENT2_EXPORT_SYMBOL void evhttp_set_timeout ( struct evhttp *  http,
int  timeout 
)

Set the timeout for an HTTP request.

Parameters
httpan evhttp object
timeoutthe timeout, in seconds
See also
evhttp_set_timeout_tv()

◆ evhttp_set_timeout_tv()

EVENT2_EXPORT_SYMBOL void evhttp_set_timeout_tv ( struct evhttp *  http,
const struct timeval *  tv 
)

Set read and write timeout for an HTTP request.

Parameters
httpan evhttp object
tvthe timeout, or NULL

For more precise control:

See also
evhttp_set_read_timeout_tv()
evhttp_set_write_timeout_tv()

◆ evhttp_set_write_timeout_tv()

EVENT2_EXPORT_SYMBOL void evhttp_set_write_timeout_tv ( struct evhttp *  http,
const struct timeval *  tv 
)

Set write timeout for an HTTP request.

Parameters
httpan evhttp object
tvthe timeout, or NULL

◆ evhttp_uri_free()

EVENT2_EXPORT_SYMBOL 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
uricontainer with parsed data
See also
evhttp_uri_parse()

◆ evhttp_uri_get_host()

const EVENT2_EXPORT_SYMBOL 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 "".

◆ evhttp_uri_join()

EVENT2_EXPORT_SYMBOL char* evhttp_uri_join ( struct evhttp_uri *  uri,
char *  buf,
size_t  limit 
)

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
uricontainer with parsed data
bufdestination buffer
limitdestination buffer size
Returns
an joined uri as string or NULL on error
See also
evhttp_uri_parse()

◆ evhttp_uri_parse_with_flags()

EVENT2_EXPORT_SYMBOL struct evhttp_uri* evhttp_uri_parse_with_flags ( const char *  source_uri,
unsigned  flags 
)

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

scheme://[[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
source_urithe request URI
flagsZero or more EVHTTP_URI_* flags to affect the behavior of the parser.
Returns
uri container to hold parsed data, or NULL if there is error
See also
evhttp_uri_free()

◆ evhttp_uri_set_flags()

EVENT2_EXPORT_SYMBOL void evhttp_uri_set_flags ( struct evhttp_uri *  uri,
unsigned  flags 
)

Changes the flags set on a given URI.

See EVHTTP_URI_* for a list of flags.

◆ evhttp_uri_set_fragment()

EVENT2_EXPORT_SYMBOL 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.

◆ evhttp_uri_set_host()

EVENT2_EXPORT_SYMBOL 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.

◆ evhttp_uri_set_path()

EVENT2_EXPORT_SYMBOL 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.

◆ evhttp_uri_set_port()

EVENT2_EXPORT_SYMBOL int evhttp_uri_set_port ( struct evhttp_uri *  uri,
int  port 
)

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.

◆ evhttp_uri_set_query()

EVENT2_EXPORT_SYMBOL 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.

◆ evhttp_uri_set_scheme()

EVENT2_EXPORT_SYMBOL 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.

◆ evhttp_uri_set_unixsocket()

EVENT2_EXPORT_SYMBOL int evhttp_uri_set_unixsocket ( struct evhttp_uri *  uri,
const char *  unixsocket 
)

Set the unix socket of an evhttp_uri, or clear the unix socket if unixsocket==NULL.

Returns 0 on success, -1 if unixsocket is not well-formed

◆ evhttp_uri_set_userinfo()

EVENT2_EXPORT_SYMBOL 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.

◆ evhttp_uridecode()

EVENT2_EXPORT_SYMBOL char* evhttp_uridecode ( const char *  uri,
int  decode_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
uria URI-encode encoded URI
decode_plusdetermines whether we convert '+' to space.
size_outif size_out is not NULL, *size_out is set to the size of the returned string
Returns
a newly allocated unencoded URI or NULL on failure

◆ evhttp_uriencode()

EVENT2_EXPORT_SYMBOL char* evhttp_uriencode ( const char *  str,
ev_ssize_t  size,
int  space_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
stran unencoded string
sizethe length of the string to encode, or -1 if the string is NUL-terminated
space_to_plusif true, space characters in 'str' are encoded as +, not %20.
Returns
a newly allocate URI-encoded string, or NULL on failure.