27 #ifndef _EVENT2_HTTP_H_
28 #define _EVENT2_HTTP_H_
54 #define HTTP_NOCONTENT 204
55 #define HTTP_MOVEPERM 301
56 #define HTTP_MOVETEMP 302
57 #define HTTP_NOTMODIFIED 304
58 #define HTTP_BADREQUEST 400
59 #define HTTP_NOTFOUND 404
60 #define HTTP_BADMETHOD 405
61 #define HTTP_ENTITYTOOLARGE 413
62 #define HTTP_EXPECTATIONFAILED 417
63 #define HTTP_INTERNAL 500
64 #define HTTP_NOTIMPLEMENTED 501
65 #define HTTP_SERVUNAVAIL 503
325 const char *reason,
struct evbuffer *databuf);
378 EVHTTP_REQ_GET = 1 << 0,
379 EVHTTP_REQ_POST = 1 << 1,
380 EVHTTP_REQ_HEAD = 1 << 2,
381 EVHTTP_REQ_PUT = 1 << 3,
382 EVHTTP_REQ_DELETE = 1 << 4,
383 EVHTTP_REQ_OPTIONS = 1 << 5,
384 EVHTTP_REQ_TRACE = 1 << 6,
385 EVHTTP_REQ_CONNECT = 1 << 7,
386 EVHTTP_REQ_PATCH = 1 << 8
429 const char *address,
unsigned short port);
455 ev_ssize_t new_max_headers_size);
458 ev_ssize_t new_max_body_size);
465 const char *address);
473 int timeout_in_secs);
485 char **address, ev_uint16_t *port);
531 int evhttp_request_get_response_code(
const struct evhttp_request *req);
580 int evhttp_add_header(
struct evkeyvalq *headers,
const char *key,
const char *value);
619 char *
evhttp_uriencode(
const char *str, ev_ssize_t size,
int space_to_plus);
824 #define EVHTTP_URI_NONCONFORMANT 0x01
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.
Definition: http.c:2853
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.
Definition: http.c:4442
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.
Definition: http.c:2222
char * evhttp_encode_uri(const char *str)
Helper function to encode a string for inclusion in a URI.
Definition: http.c:2691
struct evkeyvalq * evhttp_request_get_input_headers(struct evhttp_request *req)
Returns the input headers.
Definition: http.c:3629
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.
Definition: http.c:4503
void evhttp_set_timeout(struct evhttp *http, int timeout_in_secs)
Set the timeout for an HTTP request.
Definition: http.c:3355
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...
Definition: http.c:2657
void evhttp_connection_set_retries(struct evhttp_connection *evcon, int retry_max)
Sets the retry limit for this connection - -1 repeats indefinitely.
Definition: http.c:2145
int evhttp_remove_virtual_host(struct evhttp *http, struct evhttp *vhost)
Removes a virtual host from the http server.
Definition: http.c:3304
const 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.
Definition: http.c:4413
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 con...
Definition: http.c:4393
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.
Definition: http.c:4451
struct evbuffer * evhttp_request_get_input_buffer(struct evhttp_request *req)
Returns the input buffer.
Definition: http.c:3641
void evhttp_send_reply_chunk(struct evhttp_request *req, struct evbuffer *databuf)
Send another data chunk as part of an ongoing chunked reply.
Definition: http.c:2447
struct evhttp * evhttp_new(struct event_base *base)
Create a new HTTP server.
Definition: http.c:3206
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.
Definition: http.c:2160
int evhttp_del_cb(struct evhttp *, const char *)
Removes the callback for a specified URI.
Definition: http.c:3415
int evhttp_parse_query(const char *uri, struct evkeyvalq *headers)
Helper function to parse out arguments in a query.
Definition: http.c:2848
const struct evhttp_uri * evhttp_request_get_evhttp_uri(const struct evhttp_request *req)
Returns the request URI (parsed)
Definition: http.c:3572
void evhttp_request_set_chunked_cb(struct evhttp_request *, void(*cb)(struct evhttp_request *, void *))
Enable delivery of chunks to requestor.
Definition: http.c:3554
struct evkeyvalq * evhttp_request_get_output_headers(struct evhttp_request *req)
Returns the output headers.
Definition: http.c:3635
void evhttp_send_reply_end(struct evhttp_request *req)
Complete a chunked reply.
Definition: http.c:2473
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.
Definition: http.c:3446
int evhttp_remove_header(struct evkeyvalq *headers, const char *key)
Removes a header from a list of existing headers.
Definition: http.c:1624
int evhttp_bind_socket(struct evhttp *http, const char *address, ev_uint16_t port)
Binds an HTTP server on the specified address and port.
Definition: http.c:3071
struct evconnlistener * evhttp_bound_socket_get_listener(struct evhttp_bound_socket *bound)
Return the listener used to implement a bound socket.
Definition: http.c:3163
void evhttp_send_error(struct evhttp_request *req, int error, const char *reason)
Send an HTML error message to the client.
Definition: http.c:2358
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_so...
Definition: http.c:3141
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.
Definition: http.c:4495
evhttp_request_kind
a request object can represent either a request or a reply
Definition: http.h:390
void evhttp_free(struct evhttp *http)
Free the previously created HTTP server.
Definition: http.c:3239
struct evhttp_uri * evhttp_uri_new(void)
Return a new empty evhttp_uri with no fields set.
Definition: http.c:3905
void evhttp_connection_set_local_port(struct evhttp_connection *evcon, ev_uint16_t port)
sets the local port from which http connections are made
Definition: http.c:1187
struct evhttp_uri * evhttp_uri_parse(const char *source_uri)
Alias for evhttp_uri_parse_with_flags(source_uri, 0)
Definition: http.c:4176
struct event_base * evhttp_connection_get_base(struct evhttp_connection *req)
Returns the underlying event_base for this connection.
Definition: http.c:3548
#define evutil_socket_t
A type wide enough to hold the output of "socket()" or "accept()".
Definition: util.h:278
int evhttp_accept_socket(struct evhttp *http, evutil_socket_t fd)
Makes an HTTP server accept connections on the specified socket.
Definition: http.c:3107
void evhttp_set_max_body_size(struct evhttp *http, ev_ssize_t max_body_size)
XXX Document.
Definition: http.c:3370
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.
Definition: http.c:3118
void evhttp_request_free(struct evhttp_request *req)
Frees the request object and removes associated events.
Definition: http.c:3496
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.
Definition: http.c:3169
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.
Definition: http.c:3157
Definition: evbuffer-internal.h:78
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.
Definition: http.c:4486
void evhttp_set_max_headers_size(struct evhttp *http, ev_ssize_t max_headers_size)
XXX Document.
Definition: http.c:3361
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.
Definition: http.c:4182
void evhttp_request_own(struct evhttp_request *req)
Takes ownership of the request object.
Definition: http.c:3530
void evhttp_cancel_request(struct evhttp_request *req)
Cancels a pending HTTP request.
Definition: http.c:2274
const 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 ...
Definition: http.c:4423
void evhttp_connection_set_timeout(struct evhttp_connection *evcon, int timeout_in_secs)
Sets the timeout for events related to this connection.
Definition: http.c:2131
void evhttp_clear_headers(struct evkeyvalq *headers)
Removes all headers from the header list.
Definition: http.c:1604
enum evhttp_cmd_type evhttp_request_get_command(const struct evhttp_request *req)
Returns the request command.
Definition: http.c:3618
void evhttp_send_reply(struct evhttp_request *req, int code, const char *reason, struct evbuffer *databuf)
Send an HTML reply to the client.
Definition: http.c:2415
void evhttp_uri_free(struct evhttp_uri *uri)
Free all memory allocated for a parsed uri.
Definition: http.c:4310
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.
Definition: http.c:4403
Definition: http-internal.h:62
Common convenience functions for cross-platform portability and related socket manipulations.
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.
Definition: http.c:4475
char * evhttp_uridecode(const char *uri, int decode_plus, size_t *size_out)
Helper function to decode a URI-escaped string or HTTP parameter.
Definition: http.c:2753
char * evhttp_decode_uri(const char *uri)
Helper function to sort of decode a URI-encoded string.
Definition: http.c:2736
void evhttp_send_reply_start(struct evhttp_request *req, int code, const char *reason)
Initiate a reply that uses Transfer-Encoding chunked.
Definition: http.c:2424
const char * evhttp_request_get_uri(const struct evhttp_request *req)
Returns the request URI.
Definition: http.c:3565
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.
Definition: http.c:3385
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.
Definition: http.c:3434
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.
Definition: http.c:4459
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.
Definition: http.c:4408
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.
Definition: http.c:4329
void evhttp_set_allowed_methods(struct evhttp *http, ev_uint16_t methods)
Sets the what HTTP methods are supported in requests accepted by this server, and passed to user call...
Definition: http.c:3379
const 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.
Definition: http.c:4398
int evhttp_request_is_owned(struct evhttp_request *req)
Returns 1 if the request is owned by the user.
Definition: http.c:3536
void evhttp_connection_set_closecb(struct evhttp_connection *evcon, void(*)(struct evhttp_connection *, void *), void *)
Set a callback for connection close.
Definition: http.c:2152
struct evhttp_connection * evhttp_request_get_connection(struct evhttp_request *req)
Returns the connection object associated with the request or NULL.
Definition: http.c:3542
Definition: http-internal.h:123
char * evhttp_htmlescape(const char *html)
Escape HTML character entities in a string.
Definition: http.c:256
struct evbuffer * evhttp_request_get_output_buffer(struct evhttp_request *req)
Returns the output buffer.
Definition: http.c:3647
void evhttp_connection_free(struct evhttp_connection *evcon)
Frees an http connection.
Definition: http.c:1125
void evhttp_uri_set_flags(struct evhttp_uri *uri, unsigned flags)
Changes the flags set on a given URI.
Definition: http.c:3914
const char * evhttp_request_get_host(struct evhttp_request *req)
Returns the host associated with the request.
Definition: http.c:3580
struct evhttp_connection * evhttp_connection_base_new(struct event_base *base, struct evdns_base *dnsbase, const char *address, unsigned short port)
A connection object that can be used to for making HTTP requests.
Definition: http.c:2064
void evhttp_connection_set_local_address(struct evhttp_connection *evcon, const char *address)
sets the ip address from which http connections are made
Definition: http.c:1176
int evhttp_add_virtual_host(struct evhttp *http, const char *pattern, struct evhttp *vhost)
Adds a virtual host to the http server.
Definition: http.c:3286
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.
Definition: http.c:3081
Definition: http-internal.h:136
int evhttp_remove_server_alias(struct evhttp *http, const char *alias)
Remove a server alias from an http object.
Definition: http.c:3338
const 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...
Definition: http.c:4418
int evhttp_add_server_alias(struct evhttp *http, const char *alias)
Add a server alias to an http object.
Definition: http.c:3318
int evhttp_add_header(struct evkeyvalq *headers, const char *key, const char *value)
Adds a header to a list of existing headers.
Definition: http.c:1661
Definition: event-internal.h:167
const char * evhttp_find_header(const struct evkeyvalq *headers, const char *key)
Finds the value belonging to a header.
Definition: http.c:1591
Definition: listener.c:74
evhttp_cmd_type
The different request types supported by evhttp.
Definition: http.h:377
the request structure that a server receives.
Definition: http_struct.h:57