Skip to content

Commit

Permalink
Support 'Connection: close'
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
  • Loading branch information
zhaojh329 committed Sep 7, 2020
1 parent 28c8146 commit 9570dda
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9570dda

Please sign in to comment.