From: Niels Provos Date: Mon, 25 Feb 2008 07:49:22 +0000 (+0000) Subject: add support (without tests!) to PUT/DELETE requests; from Josh Rotenberg X-Git-Tag: release-2.0.1-alpha~415 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b14cd655d1eac14eed28ca749a4abf6889e2afca;p=libevent add support (without tests!) to PUT/DELETE requests; from Josh Rotenberg svn:r662 --- diff --git a/ChangeLog b/ChangeLog index 755e6b27..5fb74380 100644 --- a/ChangeLog +++ b/ChangeLog @@ -47,6 +47,7 @@ Changes in current version: o udpate documentation of event_loop and event_base_loop; from Tani Hosokawa. o simplify evbuffer by removing orig_buffer o do not insert event into list when evsel->add fails + o add support for PUT/DELETE requests; from Josh Rotenberg Changes in 1.4.0: diff --git a/evhttp.h b/evhttp.h index 4a85d0d9..fb496ffb 100644 --- a/evhttp.h +++ b/evhttp.h @@ -158,7 +158,7 @@ struct evhttp *evhttp_start(const char *address, u_short port); /* * Interfaces for making requests */ -enum evhttp_cmd_type { EVHTTP_REQ_GET, EVHTTP_REQ_POST, EVHTTP_REQ_HEAD }; +enum evhttp_cmd_type { EVHTTP_REQ_GET, EVHTTP_REQ_POST, EVHTTP_REQ_HEAD, EVHTTP_REQ_PUT, EVHTTP_REQ_DELETE }; enum evhttp_request_kind { EVHTTP_REQUEST, EVHTTP_RESPONSE }; diff --git a/http.c b/http.c index 0787b2e8..28a28db8 100644 --- a/http.c +++ b/http.c @@ -260,6 +260,12 @@ evhttp_method(enum evhttp_cmd_type type) case EVHTTP_REQ_HEAD: method = "HEAD"; break; + case EVHTTP_REQ_PUT: + method = "PUT"; + break; + case EVHTTP_REQ_DELETE: + method = "DELETE"; + break; default: method = NULL; break; @@ -320,8 +326,8 @@ evhttp_make_header_request(struct evhttp_connection *evcon, method, req->uri, req->major, req->minor); evbuffer_add(evcon->output_buffer, line, strlen(line)); - /* Add the content length on a post request if missing */ - if (req->type == EVHTTP_REQ_POST && + /* Add the content length on a post or put request if missing */ + if ((req->type == EVHTTP_REQ_POST || req->type == EVHTTP_REQ_PUT) && evhttp_find_header(req->output_headers, "Content-Length") == NULL){ char size[12]; snprintf(size, sizeof(size), "%ld", @@ -1112,6 +1118,10 @@ evhttp_parse_request_line(struct evhttp_request *req, char *line) req->type = EVHTTP_REQ_POST; } else if (strcmp(method, "HEAD") == 0) { req->type = EVHTTP_REQ_HEAD; + } else if (strcmp(method, "PUT") == 0) { + req->type = EVHTTP_REQ_PUT; + } else if (strcmp(method, "DELETE") == 0) { + req->type = EVHTTP_REQ_DELETE; } else { event_debug(("%s: bad method %s on request %p from %s", __func__, method, req, req->remote_host)); @@ -1342,7 +1352,8 @@ evhttp_get_body(struct evhttp_connection *evcon, struct evhttp_request *req) const char *xfer_enc; /* If this is a request without a body, then we are done */ - if (req->kind == EVHTTP_REQUEST && req->type != EVHTTP_REQ_POST) { + if (req->kind == EVHTTP_REQUEST && + (req->type != EVHTTP_REQ_POST && req->type != EVHTTP_REQ_PUT)) { evhttp_connection_done(evcon); return; }