From 9716a57aabbb2dc9b196030b3f9d837f0cd6861f Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 30 Oct 2010 17:52:40 +0200 Subject: [PATCH] Add proper support for HTTP close connection option --- gweb/gweb.c | 21 ++++++++++++++++++++- gweb/gweb.h | 3 +++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/gweb/gweb.c b/gweb/gweb.c index 5aa0697..bda2f7d 100644 --- a/gweb/gweb.c +++ b/gweb/gweb.c @@ -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); diff --git a/gweb/gweb.h b/gweb/gweb.h index 28e9acb..3fc54f8 100644 --- a/gweb/gweb.h +++ b/gweb/gweb.h @@ -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); -- 2.7.4