mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-10 13:04:23 -04:00
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:
parent
c4836d1053
commit
a67d9cb115
21
http.c
21
http.c
@ -229,6 +229,9 @@ evhttp_make_header_response(struct evhttp_connection *evcon,
|
|||||||
evhttp_add_header(req->output_headers,
|
evhttp_add_header(req->output_headers,
|
||||||
"Content-Type", "text/html; charset=ISO-8859-1");
|
"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
|
void
|
||||||
@ -402,9 +405,18 @@ evhttp_connection_done(struct evhttp_connection *evcon)
|
|||||||
* on the connection, so that we can reply to it.
|
* on the connection, so that we can reply to it.
|
||||||
*/
|
*/
|
||||||
if (evcon->flags & EVHTTP_CON_OUTGOING) {
|
if (evcon->flags & EVHTTP_CON_OUTGOING) {
|
||||||
|
struct evkeyvalq *headers = req->input_headers;
|
||||||
|
const char *connection;
|
||||||
|
|
||||||
TAILQ_REMOVE(&evcon->requests, req, next);
|
TAILQ_REMOVE(&evcon->requests, req, next);
|
||||||
req->evcon = NULL;
|
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) {
|
if (TAILQ_FIRST(&evcon->requests) != NULL) {
|
||||||
/*
|
/*
|
||||||
* We have more requests; reset the connection
|
* 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);
|
struct evhttp_request *req = TAILQ_FIRST(&evcon->requests);
|
||||||
TAILQ_REMOVE(&evcon->requests, req, next);
|
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_connection_free(evcon);
|
||||||
|
}
|
||||||
|
|
||||||
evhttp_request_free(req);
|
evhttp_request_free(req);
|
||||||
}
|
}
|
||||||
|
@ -252,14 +252,30 @@ http_connection_test(void)
|
|||||||
|
|
||||||
event_dispatch();
|
event_dispatch();
|
||||||
|
|
||||||
evhttp_connection_free(evcon);
|
|
||||||
evhttp_free(http);
|
|
||||||
|
|
||||||
if (test_ok != 1) {
|
if (test_ok != 1) {
|
||||||
fprintf(stdout, "FAILED\n");
|
fprintf(stdout, "FAILED\n");
|
||||||
exit(1);
|
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");
|
fprintf(stdout, "OK\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user