--- gtkcupsutils.c.orig	2008-03-13 14:56:55.000000000 +0000
+++ gtkcupsutils.c	2008-03-14 13:35:37.000000000 +0000
@@ -149,6 +149,8 @@
     }
 
   request->last_status = HTTP_CONTINUE;
+  request->got_status = 0;
+  request->expect = HTTP_CONTINUE;
 
   request->attempts = 0;
   request->data_io = data_io;
@@ -627,9 +629,13 @@
   httpClearFields(request->http);
   httpSetField(request->http, HTTP_FIELD_CONTENT_LENGTH, length);
   httpSetField(request->http, HTTP_FIELD_CONTENT_TYPE, "application/ipp");
+  httpSetField(request->http, HTTP_FIELD_AUTHORIZATION, httpGetAuthString(request->http));
+  httpSetExpect(request->http, request->expect);
+#if 0
 #ifdef HAVE_HTTP_AUTHSTRING
   httpSetField(request->http, HTTP_FIELD_AUTHORIZATION, request->http->authstring);
 #endif
+#endif
 
   if (httpPost(request->http, request->resource))
     {
@@ -651,6 +657,7 @@
     }
         
     request->attempts = 0;
+    request->got_status = 0;
 
     request->state = GTK_CUPS_POST_WRITE_REQUEST;
     request->ipp_request->state = IPP_IDLE;
@@ -692,35 +699,52 @@
           request->state = GTK_CUPS_POST_CHECK;
           request->poll_state = GTK_CUPS_HTTP_READ;
 	}
+	return;
+    }
+  if (httpCheck (request->http))
+    {
+	request->last_status = httpUpdate(request->http);
+	request->got_status = 1;
+	if (request->last_status != HTTP_CONTINUE) {
+	    request->state = GTK_CUPS_POST_CHECK;
+	    request->poll_state = GTK_CUPS_HTTP_READ;
+	}
     }
 }
 
 static void 
 _post_write_data (GtkCupsRequest *request)
 {
+  http_status_t http_status;
   gsize bytes;
   char buffer[_GTK_CUPS_MAX_CHUNK_SIZE];
-  http_status_t http_status;
+  GIOStatus io_status;
+  GError *error = NULL;
 
   GTK_NOTE (PRINTING,
             g_print ("CUPS Backend: %s\n", G_STRFUNC));
 
   request->poll_state = GTK_CUPS_HTTP_WRITE;
   
+  if (!request->got_status) {
   if (httpCheck (request->http))
-    http_status = httpUpdate(request->http);
-  else
-    http_status = request->last_status;
-
-  request->last_status = http_status;
-
-
-  if (http_status == HTTP_CONTINUE || http_status == HTTP_OK)
     {
-      GIOStatus io_status;
-      GError *error;
+	    request->last_status = httpUpdate(request->http);
+	    request->got_status = 1;
+	    if (request->last_status != HTTP_CONTINUE) {
+		request->state = GTK_CUPS_POST_CHECK;
+		request->poll_state = GTK_CUPS_HTTP_READ;
+		return;
+	    }
+	} else {
+	    /* need to do some sort of timeout here?
+	     * this is replacing an httpWait call in cups' request.c
+	     */
+	    return;
+	}
+  }
 
-      error = NULL;
+  http_status = request->last_status;
 
       /* send data */
       io_status =
@@ -768,6 +792,7 @@
           request->state = GTK_CUPS_POST_DONE;
 	  request->poll_state = GTK_CUPS_HTTP_IDLE;
      
+
           gtk_cups_result_set_error (request->result,
                                      GTK_CUPS_ERROR_HTTP,
                                      http_status,
@@ -777,11 +802,6 @@
           return;
         }
     }
-   else
-    {
-      request->attempts++;
-    }
-}
 
 static void 
 _post_check (GtkCupsRequest *request)
@@ -801,6 +821,12 @@
     }
   else if (http_status == HTTP_UNAUTHORIZED)
     {
+      if (!cupsDoAuthentication(request->http, "POST", request->resource)) {
+	httpFlush(request->http);
+	request->state = GTK_CUPS_POST_CONNECT;
+	httpReconnect(request->http);
+	goto again;
+      }
       /* TODO: callout for auth */
       g_warning ("NOT IMPLEMENTED: We need to prompt for authorization");
       request->state = GTK_CUPS_POST_DONE;
@@ -857,6 +883,11 @@
       request->attempts++;
       goto again;
     }
+  else if (http_status == HTTP_EXPECTATION_FAILED)
+    {
+	request->expect = (http_status_t)0;
+	goto again;
+    }
   else if (http_status != HTTP_OK)
     {
       int http_errno;
@@ -966,9 +997,13 @@
     }
 
   httpClearFields(request->http);
+  httpSetField(request->http, HTTP_FIELD_AUTHORIZATION, httpGetAuthString(request->http));
+  httpSetExpect(request->http, request->expect);
+#if 0
 #ifdef HAVE_HTTP_AUTHSTRING
   httpSetField(request->http, HTTP_FIELD_AUTHORIZATION, request->http->authstring);
 #endif
+#endif
 
   if (httpGet(request->http, request->resource))
     {
@@ -1015,6 +1050,13 @@
     }
   else if (http_status == HTTP_UNAUTHORIZED)
     {
+      if (!cupsDoAuthentication(request->http, "GET", request->resource)) {
+	httpFlush(request->http);
+	request->state = GTK_CUPS_GET_SEND;
+	httpReconnect(request->http);
+	request->last_status = HTTP_CONTINUE;
+	return;
+      }
       /* TODO: callout for auth */
       g_warning ("NOT IMPLEMENTED: We need to prompt for authorization in a non blocking manner");
       request->state = GTK_CUPS_GET_DONE;
--- gtkcupsutils.h.orig	2008-03-14 13:22:41.000000000 +0000
+++ gtkcupsutils.h	2008-03-14 11:16:38.000000000 +0000
@@ -65,6 +65,8 @@
 
   http_t *http;
   http_status_t last_status;
+  http_status_t	expect;
+  int got_status;
   ipp_t *ipp_request;
 
   gchar *server;
