]> granicus.if.org Git - libevent/commitdiff
fix a bug where event_set was called on a pending event;
authorNiels Provos <provos@gmail.com>
Wed, 6 Dec 2006 04:12:11 +0000 (04:12 +0000)
committerNiels Provos <provos@gmail.com>
Wed, 6 Dec 2006 04:12:11 +0000 (04:12 +0000)
don't read body for return codes that do not require a body;
from dug song.

svn:r294

evhttp.h
http.c

index 229259d1190f85d21c0084d40ba3700cecc5a304..b1796d0444db6462236c0d5523b87dd8b7fb3f92 100644 (file)
--- a/evhttp.h
+++ b/evhttp.h
@@ -50,8 +50,10 @@ extern "C" {
 
 /* Response codes */
 #define HTTP_OK                        200
+#define HTTP_NOCONTENT         204
 #define HTTP_MOVEPERM          301
 #define HTTP_MOVETEMP          302
+#define HTTP_NOTMODIFIED       304
 #define HTTP_BADREQUEST                400
 #define HTTP_NOTFOUND          404
 #define HTTP_SERVUNAVAIL       503
diff --git a/http.c b/http.c
index 429964611268d57f761d6acd3c9db483aaca0e6c..032ff8dea4b34d4f8f91b9c82a7900c3ac160fec 100644 (file)
--- a/http.c
+++ b/http.c
@@ -247,7 +247,10 @@ evhttp_write_buffer(struct evhttp_connection *evcon,
        evcon->cb = cb;
        evcon->cb_arg = arg;
 
-       /* xxx: maybe check if the event is still pending? */
+       /* check if the event is already pending */
+       if (event_pending(&evcon->ev, EV_WRITE|EV_TIMEOUT, NULL))
+               event_del(&evcon->ev);
+
        event_set(&evcon->ev, evcon->fd, EV_WRITE, evhttp_write, evcon);
        evhttp_add_event(&evcon->ev, evcon->timeout, HTTP_WRITE_TIMEOUT);
 }
@@ -1138,9 +1141,17 @@ evhttp_read_header(int fd, short what, void *arg)
                break;
 
        case EVHTTP_RESPONSE:
-               event_debug(("%s: starting to read body for \"%s\" on %d\n",
+               if (req->response_code == HTTP_NOCONTENT ||
+                   req->response_code == HTTP_NOTMODIFIED ||
+                   (req->response_code >= 100 && req->response_code < 200)) {
+                       event_debug(("%s: skipping body for code %d\n",
+                                       __func__, req->response_code));
+                       evhttp_connection_done(evcon);
+               } else {
+                       event_debug(("%s: start of read body for %s on %d\n",
                                __func__, req->remote_host, fd));
-               evhttp_get_body(evcon, req);
+                       evhttp_get_body(evcon, req);
+               }
                break;
 
        default: