From 9570dda5cf162a772b1c74aa6b14f3d9b565a484 Mon Sep 17 00:00:00 2001 From: Jianhui Zhao Date: Mon, 7 Sep 2020 14:16:37 +0800 Subject: [PATCH] Support 'Connection: close' Signed-off-by: Jianhui Zhao --- src/connection.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/connection.c b/src/connection.c index 95f2b3d..796ffbc 100644 --- a/src/connection.c +++ b/src/connection.c @@ -127,6 +127,10 @@ static void conn_send_head(struct uh_connection *conn, int code, int content_len conn_printf(conn, "%s", "Transfer-Encoding: chunked\r\n"); else conn_printf(conn, "Content-Length: %d\r\n", content_length); + + if (!http_should_keep_alive(&conn->parser)) + conn_printf(conn, "%s", "Connection: close\r\n"); + conn_send(conn, "\r\n", 2); } @@ -329,6 +333,8 @@ static int on_message_complete_cb(struct http_parser *parser) memset(req, 0, sizeof(struct uh_request)); + ev_io_start(conn->srv->loop, &conn->iow); + return 0; } @@ -428,7 +434,7 @@ static void conn_write_cb(struct ev_loop *loop, struct ev_io *w, int revents) conn->file.fd = -1; } - if (conn->flags & CONN_F_SEND_AND_CLOSE) + if ((conn->flags & CONN_F_SEND_AND_CLOSE) || !http_should_keep_alive(&conn->parser)) conn_free(conn); else ev_io_stop(loop, w);