summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels Provos <provos@gmail.com>2006-11-29 02:08:58 +0000
committerNiels Provos <provos@gmail.com>2006-11-29 02:08:58 +0000
commit518d530a0fe995ef5e81a5cb85cfee34478fbac5 (patch)
tree1806dd9c8aeae3a95502b3ebc33fc6d19af3e406
parentfaf7e65556ca0540ef7066315ab82271c9e2081a (diff)
downloadlibevent-518d530a0fe995ef5e81a5cb85cfee34478fbac5.tar.gz
merge from trunk:
add "Connection: close" to the output headers of the HTTP server reply; we don't currently support persistent connections; although that's going to be easy to add. svn:r283
-rw-r--r--http.c21
-rw-r--r--test/regress_http.c22
2 files changed, 39 insertions, 4 deletions
diff --git a/http.c b/http.c
index 70e05816..68cd94be 100644
--- a/http.c
+++ b/http.c
@@ -229,6 +229,9 @@ evhttp_make_header_response(struct evhttp_connection *evcon,
evhttp_add_header(req->output_headers,
"Content-Type", "text/html; charset=ISO-8859-1");
}
+ if (evhttp_find_header(req->output_headers, "Connection") == NULL) {
+ evhttp_add_header(req->output_headers, "Connection", "close");
+ }
}
void
@@ -402,9 +405,18 @@ evhttp_connection_done(struct evhttp_connection *evcon)
* on the connection, so that we can reply to it.
*/
if (evcon->flags & EVHTTP_CON_OUTGOING) {
+ struct evkeyvalq *headers = req->input_headers;
+ const char *connection;
+
TAILQ_REMOVE(&evcon->requests, req, next);
req->evcon = NULL;
+
+ /* check if we got asked to close the connection */
+ connection = evhttp_find_header(headers, "Connection");
+ if (connection != NULL && strcasecmp(connection, "close") == 0)
+ evhttp_connection_reset(evcon);
+
if (TAILQ_FIRST(&evcon->requests) != NULL) {
/*
* We have more requests; reset the connection
@@ -1119,8 +1131,15 @@ evhttp_send_done(struct evhttp_connection *evcon, void *arg)
struct evhttp_request *req = TAILQ_FIRST(&evcon->requests);
TAILQ_REMOVE(&evcon->requests, req, next);
- if (req->flags & EVHTTP_REQ_OWN_CONNECTION)
+ if (req->flags & EVHTTP_REQ_OWN_CONNECTION) {
+ const char *connection =
+ evhttp_find_header(req->output_headers, "Connection");
+ if (connection == NULL || strcasecmp(connection, "close")) {
+ event_warnx("%s: persistent connection not supported",
+ __func__);
+ }
evhttp_connection_free(evcon);
+ }
evhttp_request_free(req);
}
diff --git a/test/regress_http.c b/test/regress_http.c
index 219d5abd..cad764ce 100644
--- a/test/regress_http.c
+++ b/test/regress_http.c
@@ -252,13 +252,29 @@ http_connection_test(void)
event_dispatch();
- evhttp_connection_free(evcon);
- evhttp_free(http);
-
if (test_ok != 1) {
fprintf(stdout, "FAILED\n");
exit(1);
}
+
+ /* try to make another request over the same connection */
+ test_ok = 0;
+
+ req = evhttp_request_new(http_request_done, NULL);
+
+ /* Add the information that we care about */
+ evhttp_add_header(req->output_headers, "Host", "somehost");
+
+ /* We give ownership of the request to the connection */
+ if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/test") == -1) {
+ fprintf(stdout, "FAILED\n");
+ exit(1);
+ }
+
+ event_dispatch();
+
+ evhttp_connection_free(evcon);
+ evhttp_free(http);
fprintf(stdout, "OK\n");
}