summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorFelix Nawothnig <felix.nawothnig@gmail.com>2010-11-04 11:25:35 -0400
committerNick Mathewson <nickm@torproject.org>2010-11-04 11:53:36 -0400
commit75a73414a402005ddc2d2adde5a3acffc00d6382 (patch)
tree5a6666b28c0aa961c6505c7943f4b96514822de2 /include
parent78762383b74ad8159d8c6176fb73c9fdb9ce9623 (diff)
downloadlibevent-75a73414a402005ddc2d2adde5a3acffc00d6382.tar.gz
Define enumerators for all HTTP methods, including PATCH from RFC5789
This patch defines enumerators for all HTTP methods that exist (including PATCH introduced in RFC 5789). It also makes them bit-masky (that's not a word, is it?), breaking binary- but not source-code compatibility. evhttp now stores a bitmask specifying for which methods requests to dispatch and which ones to reject with "405 Method Not Allowed". By default that's the ones we currently have (GET, POST, HEAD, PUT, DELETE), thereby keeping functional compatibility (besides the minor change that one of the other methods will now cause 405 instead of 400. But I believe that could even be considered a bug-fix). evhttp is extended by evhttp_set_allowed_methods() with which the user can change that bitmask. no regressions here and my test-app still works. Haven't yet actually tested any of the new methods. What's obviously missing here is the special logic for the methods: OPTIONS: We should be fine here - I believe our current dispatch logic should work fine. Some convenience functions would be fine though. TRACE: I'm pretty certain we should never dispatch this to the callbacks and simply implement the necessary functionality built-in. CONNECT: Pretty straight-forward to implement (and considering the framework in which we implement it very efficient too). Should probably go built-in. PATCH: Except for checking the RFC against our pre-dispatch logic (there just might be some "MUST not have Some-Header" lurking somewhere) there is nothing to be done here, this is completely up to the user. Nothing to do.
Diffstat (limited to 'include')
-rw-r--r--include/event2/http.h26
1 files changed, 21 insertions, 5 deletions
diff --git a/include/event2/http.h b/include/event2/http.h
index e0fdefe0..45d3b245 100644
--- a/include/event2/http.h
+++ b/include/event2/http.h
@@ -57,6 +57,7 @@ struct event_base;
#define HTTP_NOTMODIFIED 304 /**< page was not modified from last */
#define HTTP_BADREQUEST 400 /**< invalid http request was made */
#define HTTP_NOTFOUND 404 /**< could not find content for uri */
+#define HTTP_BADMETHOD 405 /**< method not allowed */
#define HTTP_SERVUNAVAIL 503 /**< the server is not available */
struct evhttp;
@@ -184,6 +185,17 @@ void evhttp_set_max_headers_size(struct evhttp* http, ev_ssize_t max_headers_siz
void evhttp_set_max_body_size(struct evhttp* http, ev_ssize_t max_body_size);
/**
+ Sets the what HTTP methods are supported in requests accepted by this server.
+ If not supported they will generate a "405 Method not allowed" response.
+
+ By default this includes the following methods: GET, POST, HEAD, PUT, DELETE
+
+ @param http the http server on which to set the methods
+ @param methods bit mask constructed from evhttp_cmd_type values
+*/
+void evhttp_set_allowed_methods(struct evhttp* http, short methods);
+
+/**
Set a callback for a specified URI
@param http the http sever on which to set the callback
@@ -329,11 +341,15 @@ void evhttp_send_reply_end(struct evhttp_request *req);
/** the different request types supported by evhttp */
enum evhttp_cmd_type {
- EVHTTP_REQ_GET,
- EVHTTP_REQ_POST,
- EVHTTP_REQ_HEAD,
- EVHTTP_REQ_PUT,
- EVHTTP_REQ_DELETE
+ 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
};
/** a request object can represent either a request or a reply */