add support (without tests!) to PUT/DELETE requests; from Josh Rotenberg

svn:r662
This commit is contained in:
Niels Provos 2008-02-25 07:49:22 +00:00
parent bb914ed9af
commit b14cd655d1
3 changed files with 16 additions and 4 deletions

View File

@ -47,6 +47,7 @@ Changes in current version:
o udpate documentation of event_loop and event_base_loop; from Tani Hosokawa. o udpate documentation of event_loop and event_base_loop; from Tani Hosokawa.
o simplify evbuffer by removing orig_buffer o simplify evbuffer by removing orig_buffer
o do not insert event into list when evsel->add fails 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: Changes in 1.4.0:

View File

@ -158,7 +158,7 @@ struct evhttp *evhttp_start(const char *address, u_short port);
/* /*
* Interfaces for making requests * 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 }; enum evhttp_request_kind { EVHTTP_REQUEST, EVHTTP_RESPONSE };

17
http.c
View File

@ -260,6 +260,12 @@ evhttp_method(enum evhttp_cmd_type type)
case EVHTTP_REQ_HEAD: case EVHTTP_REQ_HEAD:
method = "HEAD"; method = "HEAD";
break; break;
case EVHTTP_REQ_PUT:
method = "PUT";
break;
case EVHTTP_REQ_DELETE:
method = "DELETE";
break;
default: default:
method = NULL; method = NULL;
break; break;
@ -320,8 +326,8 @@ evhttp_make_header_request(struct evhttp_connection *evcon,
method, req->uri, req->major, req->minor); method, req->uri, req->major, req->minor);
evbuffer_add(evcon->output_buffer, line, strlen(line)); evbuffer_add(evcon->output_buffer, line, strlen(line));
/* Add the content length on a post request if missing */ /* Add the content length on a post or put request if missing */
if (req->type == EVHTTP_REQ_POST && if ((req->type == EVHTTP_REQ_POST || req->type == EVHTTP_REQ_PUT) &&
evhttp_find_header(req->output_headers, "Content-Length") == NULL){ evhttp_find_header(req->output_headers, "Content-Length") == NULL){
char size[12]; char size[12];
snprintf(size, sizeof(size), "%ld", snprintf(size, sizeof(size), "%ld",
@ -1112,6 +1118,10 @@ evhttp_parse_request_line(struct evhttp_request *req, char *line)
req->type = EVHTTP_REQ_POST; req->type = EVHTTP_REQ_POST;
} else if (strcmp(method, "HEAD") == 0) { } else if (strcmp(method, "HEAD") == 0) {
req->type = EVHTTP_REQ_HEAD; 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 { } else {
event_debug(("%s: bad method %s on request %p from %s", event_debug(("%s: bad method %s on request %p from %s",
__func__, method, req, req->remote_host)); __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; const char *xfer_enc;
/* If this is a request without a body, then we are done */ /* 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); evhttp_connection_done(evcon);
return; return;
} }