]> granicus.if.org Git - libevent/commitdiff
add support (without tests!) to PUT/DELETE requests; from Josh Rotenberg
authorNiels Provos <provos@gmail.com>
Mon, 25 Feb 2008 07:49:22 +0000 (07:49 +0000)
committerNiels Provos <provos@gmail.com>
Mon, 25 Feb 2008 07:49:22 +0000 (07:49 +0000)
svn:r662

ChangeLog
evhttp.h
http.c

index 755e6b2741f99c29ad35e03bb1f9a163250ecd7b..5fb74380dab7853626b0397f8286da08a3799677 100644 (file)
--- 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:
index 4a85d0d971f1ee2ba868d8a5c881cb7f82d0a634..fb496ffbd6fb5c940e027faaef026f6aea05f8bc 100644 (file)
--- 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 0787b2e8fd57e26787b928bb7ae80585681721ef..28a28db87cd462b03a7a5536d6100d6962429a97 100644 (file)
--- 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;
        }