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:r259
This commit is contained in:
Niels Provos 2006-11-17 07:45:42 +00:00
parent c4836d1053
commit a67d9cb115
2 changed files with 39 additions and 4 deletions

21
http.c
View File

@ -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);
}

View File

@ -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");
}