--- libevent-2.0.3-alpha/include/event2/http.h.orig	2009-11-27 03:07:55.000000000 -0500
+++ libevent-2.0.3-alpha/include/event2/http.h	2009-11-30 09:45:19.000000000 -0500
@@ -44,6 +44,7 @@
 /* In case we haven't included the right headers yet. */
 struct evbuffer;
 struct event_base;
+struct bufferevent;
 
 /** @file http.h
  *
@@ -206,6 +207,9 @@
 void evhttp_set_gencb(struct evhttp *http,
     void (*cb)(struct evhttp_request *, void *), void *arg);
 
+void evhttp_set_bevcb(struct evhttp *http,
+    struct bufferevent* (*cb)(struct event_base *, void *), void *arg);
+
 /**
    Adds a virtual host to the http server.
 
@@ -353,6 +357,11 @@
 /** Frees the request object and removes associated events. */
 void evhttp_request_free(struct evhttp_request *req);
 
+struct evhttp_connection *evhttp_connection_base_bufferevent_new(
+	struct event_base *base, struct evdns_base *dnsbase, struct bufferevent* bev, const char *address, unsigned short port);
+
+struct bufferevent* evhttp_connection_get_bufferevent(struct evhttp_connection *evcon);
+
 /**
  * A connection object that can be used to for making HTTP requests.  The
  * connection object tries to establish the connection when it is given an
--- libevent-2.0.3-alpha/http.c.orig	2009-11-27 02:27:41.000000000 -0500
+++ libevent-2.0.3-alpha/http.c	2009-12-02 01:05:03.000000000 -0500
@@ -1143,6 +1143,7 @@
 		evhttp_connection_fail(evcon, EVCON_HTTP_TIMEOUT);
 	} else if (what & (BEV_EVENT_EOF|BEV_EVENT_ERROR)) {
 		evhttp_connection_fail(evcon, EVCON_HTTP_EOF);
+	} else if (what == BEV_EVENT_CONNECTED) {
 	} else {
 		evhttp_connection_fail(evcon, EVCON_HTTP_BUFFER_ERROR);
 	}
@@ -1734,7 +1737,7 @@
 }
 
 struct evhttp_connection *
-evhttp_connection_base_new(struct event_base *base, struct evdns_base *dnsbase,
+evhttp_connection_base_bufferevent_new(struct event_base *base, struct evdns_base *dnsbase, struct bufferevent* bev,
     const char *address, unsigned short port)
 {
 	struct evhttp_connection *evcon = NULL;
@@ -1759,13 +1762,19 @@
 		event_warn("%s: strdup failed", __func__);
 		goto error;
 	}
-
-	if ((evcon->bufev = bufferevent_new(-1,
-		    evhttp_read_cb,
-		    evhttp_write_cb,
-		    evhttp_error_cb, evcon)) == NULL) {
-		event_warn("%s: bufferevent_new failed", __func__);
-		goto error;
+	
+	if (bev == NULL) {
+		if ((evcon->bufev = bufferevent_new(-1,
+					evhttp_read_cb,
+					evhttp_write_cb,
+					evhttp_error_cb, evcon)) == NULL) {
+			event_warn("%s: bufferevent_new failed", __func__);
+			goto error;
+		}
+	}
+	else {
+		bufferevent_setcb(bev, evhttp_read_cb, evhttp_write_cb, evhttp_error_cb, evcon);
+		evcon->bufev = bev;
 	}
 
 	evcon->state = EVCON_DISCONNECTED;
@@ -1784,6 +1793,18 @@
 	return (NULL);
 }
 
+struct bufferevent* evhttp_connection_get_bufferevent(struct evhttp_connection *evcon)
+{
+	return evcon->bufev;
+}
+
+struct evhttp_connection *
+evhttp_connection_base_new(struct event_base *base, struct evdns_base *dnsbase,
+    const char *address, unsigned short port)
+{
+	return evhttp_connection_base_bufferevent_new(base, dnsbase, NULL, address, port);
+}
+
 void
 evhttp_connection_set_base(struct evhttp_connection *evcon,
     struct event_base *base)
@@ -2742,6 +2764,14 @@
 	http->gencbarg = cbarg;
 }
 
+void
+evhttp_set_bevcb(struct evhttp *http,
+    struct bufferevent* (*cb)(struct event_base *, void *), void *cbarg)
+{
+	http->bevcb = cb;
+	http->bevcbarg = cbarg;
+}
+
 /*
  * Request related functions
  */
@@ -2893,6 +2923,7 @@
 {
 	struct evhttp_connection *evcon;
 	char *hostname = NULL, *portname = NULL;
+	struct bufferevent* bev = NULL;
 
 	name_from_addr(sa, salen, &hostname, &portname);
 	if (hostname == NULL || portname == NULL) {
@@ -2905,8 +2936,11 @@
 			__func__, hostname, portname, fd));
 
 	/* we need a connection object to put the http request on */
-	evcon = evhttp_connection_base_new(
-		http->base, NULL, hostname, atoi(portname));
+	if (http->bevcb != NULL) {
+		bev = (*http->bevcb)(http->base, http->bevcbarg);
+	}
+	evcon = evhttp_connection_base_bufferevent_new(
+		http->base, NULL, bev, hostname, atoi(portname));
 	mm_free(hostname);
 	mm_free(portname);
 	if (evcon == NULL)
--- libevent-2.0.3-alpha/http-internal.h.orig	2009-11-27 02:24:41.000000000 -0500
+++ libevent-2.0.3-alpha/http-internal.h	2009-11-30 09:34:35.000000000 -0500
@@ -138,6 +138,8 @@
 
 	void (*gencb)(struct evhttp_request *req, void *);
 	void *gencbarg;
+	struct bufferevent* (*bevcb)(struct event_base *, void *);
+	void *bevcbarg;
 
 	struct event_base *base;
 };
