Add proper support for HTTP close connection option
authorMarcel Holtmann <marcel@holtmann.org>
Sat, 30 Oct 2010 15:52:40 +0000 (17:52 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Sat, 30 Oct 2010 15:52:40 +0000 (17:52 +0200)
gweb/gweb.c
gweb/gweb.h

index 5aa0697..bda2f7d 100644 (file)
@@ -72,6 +72,7 @@ struct _GWeb {
        GResolv *resolv;
        char *accept_option;
        char *user_agent;
+       gboolean close_connection;
 
        GWebDebugFunc debug_func;
        gpointer debug_data;
@@ -154,6 +155,7 @@ GWeb *g_web_new(int index)
 
        web->accept_option = g_strdup("*/*");
        web->user_agent = g_strdup_printf("GWeb/%s", VERSION);
+       web->close_connection = FALSE;
 
        return web;
 }
@@ -266,6 +268,22 @@ gboolean g_web_set_user_agent(GWeb *web, const char *format, ...)
        return result;
 }
 
+void g_web_set_close_connection(GWeb *web, gboolean enabled)
+{
+       if (web == NULL)
+               return;
+
+       web->close_connection = enabled;
+}
+
+gboolean g_web_get_close_connection(GWeb *web)
+{
+       if (web == NULL)
+               return FALSE;
+
+       return web->close_connection;
+}
+
 static gboolean received_data(GIOChannel *channel, GIOCondition cond,
                                                        gpointer user_data)
 {
@@ -375,7 +393,8 @@ static void start_request(struct web_session *session)
        if (session->web->accept_option != NULL)
                g_string_append_printf(buf, "Accept: %s\r\n",
                                                session->web->accept_option);
-       g_string_append(buf, "Connection: close\r\n");
+       if (session->web->close_connection == TRUE)
+               g_string_append(buf, "Connection: close\r\n");
        g_string_append(buf, "\r\n");
        str = g_string_free(buf, FALSE);
 
index 28e9acb..3fc54f8 100644 (file)
@@ -59,6 +59,9 @@ gboolean g_web_set_accept(GWeb *web, const char *format, ...)
 gboolean g_web_set_user_agent(GWeb *web, const char *format, ...)
                                __attribute__((format(printf, 2, 3)));
 
+void g_web_set_close_connection(GWeb *web, gboolean enabled);
+gboolean g_web_get_close_connection(GWeb *web);
+
 guint g_web_request(GWeb *web, GWebMethod method, const char *url,
                                GWebResultFunc func, gpointer user_data);