MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
evhttp.h File Reference
#include <event.h>
Include dependency graph for evhttp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  evhttp_request

Macros

#define HTTP_OK   200
#define HTTP_NOCONTENT   204
#define HTTP_MOVEPERM   301
#define HTTP_MOVETEMP   302
#define HTTP_NOTMODIFIED   304
#define HTTP_BADREQUEST   400
#define HTTP_NOTFOUND   404
#define HTTP_SERVUNAVAIL   503
#define EVHTTP_REQ_OWN_CONNECTION   0x0001
#define EVHTTP_PROXY_REQUEST   0x0002

Enumerations

enum  evhttp_cmd_type { EVHTTP_REQ_GET, EVHTTP_REQ_POST, EVHTTP_REQ_HEAD }
enum  evhttp_request_kind { EVHTTP_REQUEST, EVHTTP_RESPONSE }

Functions

struct evhttpevhttp_new (struct event_base *base)
int evhttp_bind_socket (struct evhttp *http, const char *address, u_short port)
int evhttp_accept_socket (struct evhttp *http, int fd)
void evhttp_free (struct evhttp *http)
void evhttp_set_cb (struct evhttp *, const char *, void(*)(struct evhttp_request *, void *), void *)
int evhttp_del_cb (struct evhttp *, const char *)
void evhttp_set_gencb (struct evhttp *, void(*)(struct evhttp_request *, void *), void *)
void evhttp_set_timeout (struct evhttp *, int timeout_in_secs)
void evhttp_send_error (struct evhttp_request *req, int error, const char *reason)
void evhttp_send_reply (struct evhttp_request *req, int code, const char *reason, struct evbuffer *databuf)
void evhttp_send_reply_start (struct evhttp_request *, int, const char *)
void evhttp_send_reply_chunk (struct evhttp_request *, struct evbuffer *)
void evhttp_send_reply_end (struct evhttp_request *)
struct evhttpevhttp_start (const char *address, u_short port)
struct evhttp_requestevhttp_request_new (void(*cb)(struct evhttp_request *, void *), void *arg)
void evhttp_request_set_chunked_cb (struct evhttp_request *, void(*cb)(struct evhttp_request *, void *))
void evhttp_request_free (struct evhttp_request *req)
struct evhttp_connectionevhttp_connection_new (const char *address, unsigned short port)
void evhttp_connection_free (struct evhttp_connection *evcon)
void evhttp_connection_set_local_address (struct evhttp_connection *evcon, const char *address)
void evhttp_connection_set_local_port (struct evhttp_connection *evcon, unsigned short port)
void evhttp_connection_set_timeout (struct evhttp_connection *evcon, int timeout_in_secs)
void evhttp_connection_set_retries (struct evhttp_connection *evcon, int retry_max)
void evhttp_connection_set_closecb (struct evhttp_connection *evcon, void(*)(struct evhttp_connection *, void *), void *)
void evhttp_connection_set_base (struct evhttp_connection *evcon, struct event_base *base)
void evhttp_connection_get_peer (struct evhttp_connection *evcon, char **address, u_short *port)
int evhttp_make_request (struct evhttp_connection *evcon, struct evhttp_request *req, enum evhttp_cmd_type type, const char *uri)
const char * evhttp_request_uri (struct evhttp_request *req)
const char * evhttp_find_header (const struct evkeyvalq *, const char *)
int evhttp_remove_header (struct evkeyvalq *, const char *)
int evhttp_add_header (struct evkeyvalq *, const char *, const char *)
void evhttp_clear_headers (struct evkeyvalq *)
char * evhttp_encode_uri (const char *uri)
char * evhttp_decode_uri (const char *uri)
void evhttp_parse_query (const char *uri, struct evkeyvalq *headers)
char * evhttp_htmlescape (const char *html)

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.

Definition in file evhttp.h.

Function Documentation

int evhttp_accept_socket ( struct evhttp http,
int  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_free(), evhttp_bind_socket()

Definition at line 2280 of file http.c.

Here is the call graph for this function:

Here is the caller graph for this function:

int evhttp_bind_socket ( struct evhttp http,
const char *  address,
u_short  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
a newly allocated evhttp struct
See Also
evhttp_free()

Definition at line 2256 of file http.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void evhttp_connection_free ( struct evhttp_connection evcon)

Frees an http connection

Definition at line 987 of file http.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void evhttp_connection_get_peer ( struct evhttp_connection evcon,
char **  address,
u_short *  port 
)

Get the remote address and port associated with this connection.

Definition at line 1755 of file http.c.

Here is the call graph for this function:

Here is the caller graph for this function:

struct evhttp_connection* evhttp_connection_new ( const char *  address,
unsigned short  port 
)
read

A connection object that can be used to for making HTTP requests. The connection object tries to establish the connection when it is given an http request object.

Definition at line 1681 of file http.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void evhttp_connection_set_base ( struct evhttp_connection evcon,
struct event_base base 
)

Associates an event base with the connection - can only be called on a freshly created connection object that has not been used yet.

Definition at line 1724 of file http.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void evhttp_connection_set_closecb ( struct evhttp_connection evcon,
void(*)(struct evhttp_connection *, void *)  ,
void *   
)

Set a callback for connection close.

Definition at line 1747 of file http.c.

Here is the call graph for this function:

Here is the caller graph for this function:

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

sets the ip address from which http connections are made

Definition at line 1033 of file http.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void evhttp_connection_set_local_port ( struct evhttp_connection evcon,
unsigned short  port 
)

sets the local port from which http connections are made

Definition at line 1044 of file http.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void evhttp_connection_set_retries ( struct evhttp_connection evcon,
int  retry_max 
)

Sets the retry limit for this connection - -1 repeats indefnitely

Definition at line 1740 of file http.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void evhttp_connection_set_timeout ( struct evhttp_connection evcon,
int  timeout_in_secs 
)

Sets the timeout for events related to this connection

Definition at line 1733 of file http.c.

Here is the call graph for this function:

Here is the caller graph for this function:

char* evhttp_decode_uri ( const char *  uri)

Helper function to decode a URI.

The returned string must be freed by the caller.

Parameters
urian encoded URI
Returns
a newly allocated unencoded URI

Definition at line 2099 of file http.c.

Here is the call graph for this function:

Here is the caller graph for this function:

int evhttp_del_cb ( struct evhttp ,
const char *   
)

Removes the callback for a specified URI

Definition at line 2410 of file http.c.

Here is the call graph for this function:

Here is the caller graph for this function:

char* evhttp_encode_uri ( const char *  uri)

Helper function to encode a URI.

The returned string must be freed by the caller.

Parameters
urian unencoded URI
Returns
a newly allocated URI-encoded string

Definition at line 2049 of file http.c.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 2355 of file http.c.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 280 of file http.c.

Here is the call graph for this function:

Here is the caller graph for this function:

int evhttp_make_request ( struct evhttp_connection evcon,
struct evhttp_request req,
enum evhttp_cmd_type  type,
const char *  uri 
)

The connection gets ownership of the request

Definition at line 1803 of file http.c.

Here is the call graph for this function:

Here is the caller graph for this function:

struct evhttp* evhttp_new ( struct event_base base)
read

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

Definition at line 2328 of file http.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void 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"

Parameters
urithe request URI
headersthe head of the evkeyval queue

Definition at line 2119 of file http.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void evhttp_request_free ( struct evhttp_request req)

Frees the request object and removes associated events.

Definition at line 2488 of file http.c.

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Definition at line 2441 of file http.c.

Here is the call graph for this function:

Here is the caller graph for this function:

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

enable delivery of chunks to requestor

Definition at line 2513 of file http.c.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 1894 of file http.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void evhttp_send_reply ( struct evhttp_request req,
int  code,
const char *  reason,
struct evbuffer databuf 
)

Send an HTML reply to the client.

Parameters
reqa request object
codethe HTTP response code to send
reasona brief message to send with the response code
databufthe body of the response

Definition at line 1938 of file http.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void evhttp_set_cb ( struct evhttp ,
const char *  ,
void(*)(struct evhttp_request *, void *)  ,
void *   
)

Set a callback for a specified URI

Definition at line 2394 of file http.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void evhttp_set_gencb ( struct evhttp ,
void(*)(struct evhttp_request *, void *)  ,
void *   
)

Set a callback for all requests that are not caught by specific callbacks

Definition at line 2429 of file http.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void evhttp_set_timeout ( struct evhttp ,
int  timeout_in_secs 
)

Set the timeout for an HTTP request.

Parameters
httpan evhttp object
timeout_in_secsthe timeout, in seconds

Definition at line 2388 of file http.c.

Here is the call graph for this function:

Here is the caller graph for this function:

struct evhttp* evhttp_start ( const char *  address,
u_short  port 
)
read

Start an HTTP server on the specified address and port

DEPRECATED: it does not allow an event base to be specified

Parameters
addressthe address to which the HTTP server should be bound
portthe port number on which the HTTP server should listen
Returns
an struct evhttp object

Definition at line 2342 of file http.c.

Here is the call graph for this function:

Here is the caller graph for this function: