Merge branch '20_empty_body'

This commit is contained in:
Nick Mathewson 2010-11-26 12:59:02 -05:00
commit d40aa673c2

30
http.c
View File

@ -1734,6 +1734,28 @@ evhttp_get_body_length(struct evhttp_request *req)
return (0); return (0);
} }
static int
evhttp_method_may_have_body(enum evhttp_cmd_type type)
{
switch (type) {
case EVHTTP_REQ_POST:
case EVHTTP_REQ_PUT:
case EVHTTP_REQ_PATCH:
return 1;
case EVHTTP_REQ_TRACE:
return 0;
/* XXX May any of the below methods have a body? */
case EVHTTP_REQ_GET:
case EVHTTP_REQ_HEAD:
case EVHTTP_REQ_DELETE:
case EVHTTP_REQ_OPTIONS:
case EVHTTP_REQ_CONNECT:
return 0;
default:
return 0;
}
}
static void static void
evhttp_get_body(struct evhttp_connection *evcon, struct evhttp_request *req) evhttp_get_body(struct evhttp_connection *evcon, struct evhttp_request *req)
{ {
@ -1741,7 +1763,7 @@ evhttp_get_body(struct evhttp_connection *evcon, struct evhttp_request *req)
/* 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 && if (req->kind == EVHTTP_REQUEST &&
(req->type != EVHTTP_REQ_POST && req->type != EVHTTP_REQ_PUT)) { !evhttp_method_may_have_body(req->type)) {
evhttp_connection_done(evcon); evhttp_connection_done(evcon);
return; return;
} }
@ -1756,6 +1778,12 @@ evhttp_get_body(struct evhttp_connection *evcon, struct evhttp_request *req)
EVCON_HTTP_INVALID_HEADER); EVCON_HTTP_INVALID_HEADER);
return; return;
} }
if (req->kind == EVHTTP_REQUEST && req->ntoread < 1) {
/* An incoming request with no content-length and no
* transfer-encoding has no body. */
evhttp_connection_done(evcon);
return;
}
} }
evhttp_read_body(evcon, req); evhttp_read_body(evcon, req);
/* note the request may have been freed in evhttp_read_body */ /* note the request may have been freed in evhttp_read_body */