diff options
author | Joe Shaw <joe@ximian.com> | 2002-07-02 17:42:27 +0000 |
---|---|---|
committer | Joe Shaw <joeshaw@src.gnome.org> | 2002-07-02 17:42:27 +0000 |
commit | 07726a7cbda199c44aaa5f22328f02f5d6addb6d (patch) | |
tree | a314c391815e5778f78c76b2089140c7c1ceb0c1 | |
parent | fdfb9cc952112e40b7886bf27e87c47b460dda60 (diff) | |
download | libsoup-07726a7cbda199c44aaa5f22328f02f5d6addb6d.tar.gz |
Added. Checks to see if we should keep the connection around, and obeys
2002-07-02 Joe Shaw <joe@ximian.com>
* src/libsoup/soup-server.c (check_close_connection): Added.
Checks to see if we should keep the connection around, and obeys
the spec (RFC 2616: 8.1.2.1 Negotiation). HTTP 1.0 connections
should close by default unless "Connection: keep-alive" is
specified, and HTTP 1.1 connections should stay open by default
unless "Connection: close" is specified.
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | libsoup/soup-server.c | 40 |
2 files changed, 43 insertions, 6 deletions
@@ -1,3 +1,12 @@ +2002-07-02 Joe Shaw <joe@ximian.com> + + * src/libsoup/soup-server.c (check_close_connection): Added. + Checks to see if we should keep the connection around, and obeys + the spec (RFC 2616: 8.1.2.1 Negotiation). HTTP 1.0 connections + should close by default unless "Connection: keep-alive" is + specified, and HTTP 1.1 connections should stay open by default + unless "Connection: close" is specified. + 2002-07-01 Joe Shaw <joe@ximian.com> * src/libsoup/soup-transfer.c (soup_transfer_read_cb): Back out my diff --git a/libsoup/soup-server.c b/libsoup/soup-server.c index 5b3fe462..38ead4c1 100644 --- a/libsoup/soup-server.c +++ b/libsoup/soup-server.c @@ -200,6 +200,33 @@ static gboolean start_another_request (GIOChannel *serv_chan, GIOCondition condition, gpointer user_data); +static gboolean +check_close_connection (SoupMessage *msg) +{ + const char *connection_hdr; + gboolean close_connection; + + connection_hdr = soup_message_get_header (msg->request_headers, + "Connection"); + + if (msg->priv->http_version == SOUP_HTTP_1_0) { + if (connection_hdr && g_strcasecmp (connection_hdr, + "keep-alive") == 0) + close_connection = FALSE; + else + close_connection = TRUE; + } + else { + if (connection_hdr && g_strcasecmp (connection_hdr, + "close") == 0) + close_connection = TRUE; + else + close_connection = FALSE; + } + + return close_connection; +} /* check_close_connection */ + static void destroy_message (SoupMessage *msg) { @@ -208,11 +235,12 @@ destroy_message (SoupMessage *msg) SoupServerMessage *server_msg = msg->priv->server_msg; if (server_sock) { - if (server_msg && msg->priv->http_version == SOUP_HTTP_1_0) - /* - * Close the socket if we are using HTTP/1.0 and - * did not specify a Content-Length response header. - */ + /* + * Close the socket if we're using HTTP/1.0 and + * "Connection: keep-alive" isn't specified, or if we're + * using HTTP/1.1 and "Connection: close" was specified. + */ + if (check_close_connection (msg)) soup_socket_unref (server_sock); else { /* @@ -426,7 +454,7 @@ get_response_header (SoupMessage *req, { GString *ret = g_string_new (NULL); - if (status_line) + if (status_line) g_string_sprintfa (ret, "HTTP/1.1 %d %s\r\n", req->errorcode, |