diff options
author | Niels Provos <provos@gmail.com> | 2006-11-29 02:08:58 +0000 |
---|---|---|
committer | Niels Provos <provos@gmail.com> | 2006-11-29 02:08:58 +0000 |
commit | 518d530a0fe995ef5e81a5cb85cfee34478fbac5 (patch) | |
tree | 1806dd9c8aeae3a95502b3ebc33fc6d19af3e406 | |
parent | faf7e65556ca0540ef7066315ab82271c9e2081a (diff) | |
download | libevent-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.c | 21 | ||||
-rw-r--r-- | test/regress_http.c | 22 |
2 files changed, 39 insertions, 4 deletions
@@ -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"); } |