--- gtk+-2.10.6/modules/printbackends/cups/gtkcupsutils.c	2006-10-03 11:14:38.000000000 -0700
+++ gtk+-2.10.6-shared/modules/printbackends/cups/gtkcupsutils.c	2007-06-28 14:36:36.000000000 -0700
@@ -47,6 +47,8 @@ static void _get_send           (GtkCups
 static void _get_check          (GtkCupsRequest *request);
 static void _get_read_data      (GtkCupsRequest *request);
 
+static http_t *g_http = NULL;
+
 struct _GtkCupsResult
 {
   gchar *error_msg;
@@ -130,7 +132,12 @@ gtk_cups_request_new (http_t *connection
   else
     {
       request->http = NULL;
-      request->http = httpConnectEncrypt (request->server, ippPort(), cupsEncryption());
+      if (g_http) {
+        request->http = g_http;
+      } else {
+        request->http = httpConnectEncrypt (request->server, ippPort(), cupsEncryption());
+        g_http = request->http;
+      }
 
       if (request->http)
         httpBlocking (request->http, 0);
@@ -182,7 +189,8 @@ gtk_cups_request_free (GtkCupsRequest *r
 {
   if (request->own_http)
     if (request->http)
-      httpClose (request->http);
+      if (request->http != g_http)
+        httpClose (request->http);
   
   if (request->ipp_request)
     ippDelete (request->ipp_request);
@@ -493,7 +501,12 @@ _connect (GtkCupsRequest *request)
 
   if (request->http == NULL)
     {
-      request->http = httpConnectEncrypt (request->server, ippPort(), cupsEncryption());
+      if (g_http) {
+        request->http = g_http;
+      } else {
+        request->http = httpConnectEncrypt (request->server, ippPort(), cupsEncryption());
+        g_http = request->http;
+      }
 
       if (request->http == NULL)
         request->attempts++;
@@ -613,7 +626,9 @@ _post_write_data (GtkCupsRequest *reques
     http_status = request->last_status;
 
   request->last_status = http_status;
-
+  
+  if (http_status == HTTP_CLOSE)
+    g_http = NULL;
 
   if (http_status == HTTP_CONTINUE || http_status == HTTP_OK)
     {
@@ -717,10 +732,13 @@ _post_check (GtkCupsRequest *request)
           return;
         }
     }
-/* TODO: detect ssl in configure.ac */
-#if HAVE_SSL
   else if (http_status == HTTP_UPGRADE_REQUIRED)
+
     {
+      cupsSetEncryption (HTTP_ENCRYPT_REQUIRED);
+      request->state = GTK_CUPS_POST_CONNECT;
+      g_http = NULL;
+      
       /* Flush any error message... */
       httpFlush (request->http);
 
@@ -733,7 +751,6 @@ _post_check (GtkCupsRequest *request)
       request->attempts++;
       goto again;
     }
-#endif 
   else if (http_status != HTTP_OK)
     {
       int http_errno;
@@ -746,7 +763,7 @@ _post_check (GtkCupsRequest *request)
         {
           request->state = GTK_CUPS_POST_DONE;
           gtk_cups_result_set_error (request->result, "HTTP Error in POST %s", strerror (http_errno));
-         request->poll_state = GTK_CUPS_HTTP_IDLE;
+	  request->poll_state = GTK_CUPS_HTTP_IDLE;
  
           httpFlush(request->http); 
           return;
@@ -757,7 +774,8 @@ _post_check (GtkCupsRequest *request)
       httpFlush(request->http); 
       
       request->last_status = HTTP_CONTINUE;
-      httpClose (request->http);
+      if (request->http != g_http)
+        httpClose (request->http);
       request->http = NULL;
       return;  
     }
@@ -774,6 +792,8 @@ _post_check (GtkCupsRequest *request)
     http_status = httpUpdate (request->http);
 
   request->last_status = http_status;
+  if (http_status == HTTP_CLOSE)
+    g_http = NULL;
 }
 
 static void 
@@ -879,10 +899,11 @@ _get_check (GtkCupsRequest *request)
       gtk_cups_result_set_error (request->result, "Can't prompt for authorization");
       return;
     }
-/* TODO: detect ssl in configure.ac */
-#if HAVE_SSL
   else if (http_status == HTTP_UPGRADE_REQUIRED)
     {
+      cupsSetEncryption (HTTP_ENCRYPT_REQUIRED);
+      request->state = GTK_CUPS_GET_CONNECT;
+      g_http = NULL;
       /* Flush any error message... */
       httpFlush (request->http);
 
@@ -895,7 +916,6 @@ _get_check (GtkCupsRequest *request)
       request->attempts++;
       goto again;
     }
-#endif 
   else if (http_status != HTTP_OK)
     {
       int http_errno;
@@ -916,7 +936,8 @@ _get_check (GtkCupsRequest *request)
 
       request->poll_state = GTK_CUPS_HTTP_IDLE;
       httpFlush (request->http);
-      httpClose (request->http);
+      if (request->http != g_http)
+        httpClose (request->http);
       request->last_status = HTTP_CONTINUE;
       request->http = NULL;
       return;
@@ -936,6 +957,8 @@ _get_check (GtkCupsRequest *request)
 
   request->last_status = http_status;
 
+  if (http_status == HTTP_CLOSE)
+    g_http = NULL;
 }
 
 static void 
