Index: libsoup-2.25.5/libsoup/soup-message-io.c
===================================================================
--- libsoup-2.25.5.orig/libsoup/soup-message-io.c	2009-02-11 09:36:58.000000000 +0100
+++ libsoup-2.25.5/libsoup/soup-message-io.c	2009-02-11 09:42:31.000000000 +0100
@@ -157,9 +157,8 @@
 }
 
 #define SOUP_MESSAGE_IO_EOL            "\r\n"
-#define SOUP_MESSAGE_IO_EOL_LEN        2
 #define SOUP_MESSAGE_IO_DOUBLE_EOL     "\r\n\r\n"
-#define SOUP_MESSAGE_IO_DOUBLE_EOL_LEN 4
+#define SOUP_MESSAGE_IO_DOUBLE_LF      "\n\n"
 
 static void
 soup_message_io_finished (SoupMessage *msg)
@@ -224,22 +223,21 @@
  * function returns %FALSE, the caller should return immediately.
  */
 static gboolean
-read_metadata (SoupMessage *msg, const char *boundary)
+read_metadata (SoupMessage *msg, GPtrArray *boundaries, gint *len)
 {
 	SoupMessagePrivate *priv = SOUP_MESSAGE_GET_PRIVATE (msg);
 	SoupMessageIOData *io = priv->io_data;
 	SoupSocketIOStatus status;
 	guchar read_buf[RESPONSE_BLOCK_SIZE];
-	guint boundary_len = strlen (boundary);
 	gsize nread;
 	gboolean done;
 	GError *error = NULL;
-
+	
 	do {
 		status = soup_socket_read_until (io->sock, read_buf,
 						 sizeof (read_buf),
-						 boundary, boundary_len,
-						 &nread, &done, NULL, &error);
+						 boundaries,
+						 &nread, &done, NULL, len, &error);
 		switch (status) {
 		case SOUP_SOCKET_OK:
 			g_byte_array_append (io->read_meta_buf, read_buf, nread);
@@ -605,7 +603,7 @@
 
 	case SOUP_MESSAGE_IO_STATE_CHUNK_END:
 		if (!write_data (msg, SOUP_MESSAGE_IO_EOL,
-				 SOUP_MESSAGE_IO_EOL_LEN, FALSE))
+				 strlen(SOUP_MESSAGE_IO_EOL), FALSE))
 			return;
 
 		io->write_state = SOUP_MESSAGE_IO_STATE_CHUNK_SIZE;
@@ -614,7 +612,7 @@
 
 	case SOUP_MESSAGE_IO_STATE_TRAILERS:
 		if (!write_data (msg, SOUP_MESSAGE_IO_EOL,
-				 SOUP_MESSAGE_IO_EOL_LEN, FALSE))
+				 strlen(SOUP_MESSAGE_IO_EOL), FALSE))
 			return;
 
 		io->write_state = SOUP_MESSAGE_IO_STATE_FINISHING;
@@ -654,6 +652,8 @@
 	SoupMessagePrivate *priv = SOUP_MESSAGE_GET_PRIVATE (msg);
 	SoupMessageIOData *io = priv->io_data;
 	guint status;
+	gint len;
+	GPtrArray *boundaries;
 
  read_more:
 	switch (io->read_state) {
@@ -662,10 +662,17 @@
 
 
 	case SOUP_MESSAGE_IO_STATE_HEADERS:
-		if (!read_metadata (msg, SOUP_MESSAGE_IO_DOUBLE_EOL))
+		/* Create an array of boundaries */
+		boundaries = g_ptr_array_new ();
+		g_ptr_array_add (boundaries, (gpointer) SOUP_MESSAGE_IO_DOUBLE_EOL);
+		g_ptr_array_add (boundaries, (gpointer) SOUP_MESSAGE_IO_DOUBLE_LF);
+		if (!read_metadata (msg, boundaries, &len)) {
+			(void)g_ptr_array_free (boundaries, FALSE);
 			return;
+		}
+    		(void)g_ptr_array_free (boundaries, FALSE);
 
-		io->read_meta_buf->len -= SOUP_MESSAGE_IO_EOL_LEN;
+		io->read_meta_buf->len -= (len - 2);
 		io->read_meta_buf->data[io->read_meta_buf->len] = '\0';
 		status = io->parse_headers_cb (msg, (char *)io->read_meta_buf->data,
 					       io->read_meta_buf->len,
@@ -764,8 +771,15 @@
 
 
 	case SOUP_MESSAGE_IO_STATE_CHUNK_SIZE:
-		if (!read_metadata (msg, SOUP_MESSAGE_IO_EOL))
+		/* Create an array of boundaries */
+		boundaries = g_ptr_array_new ();
+		g_ptr_array_add (boundaries, (gpointer) SOUP_MESSAGE_IO_EOL);
+
+		if (!read_metadata (msg, boundaries, &len)) {
+			(void)g_ptr_array_free (boundaries, FALSE);
 			return;
+		}
+		(void)g_ptr_array_free (boundaries, FALSE);
 
 		io->read_length = strtoul ((char *)io->read_meta_buf->data, NULL, 16);
 		g_byte_array_set_size (io->read_meta_buf, 0);
@@ -786,8 +800,14 @@
 
 
 	case SOUP_MESSAGE_IO_STATE_CHUNK_END:
-		if (!read_metadata (msg, SOUP_MESSAGE_IO_EOL))
+		/* Create an array of boundaries */
+		boundaries = g_ptr_array_new ();
+		g_ptr_array_add (boundaries, (gpointer) SOUP_MESSAGE_IO_EOL);
+		if (!read_metadata (msg, boundaries, &len)) {
+			(void)g_ptr_array_free (boundaries, FALSE);
 			return;
+		}
+		(void)g_ptr_array_free (boundaries, FALSE);
 
 		g_byte_array_set_size (io->read_meta_buf, 0);
 		io->read_state = SOUP_MESSAGE_IO_STATE_CHUNK_SIZE;
@@ -795,10 +815,16 @@
 
 
 	case SOUP_MESSAGE_IO_STATE_TRAILERS:
-		if (!read_metadata (msg, SOUP_MESSAGE_IO_EOL))
+		/* Create an array of boundaries */
+		boundaries = g_ptr_array_new ();
+		g_ptr_array_add (boundaries, (gpointer) SOUP_MESSAGE_IO_EOL);
+		if (!read_metadata (msg, boundaries, &len)) {
+			(void)g_ptr_array_free (boundaries, FALSE);		  
 			return;
+		}
+		(void)g_ptr_array_free (boundaries, FALSE);
 
-		if (io->read_meta_buf->len == SOUP_MESSAGE_IO_EOL_LEN)
+		if (io->read_meta_buf->len == len)
 			goto got_body;
 
 		/* FIXME: process trailers */
Index: libsoup-2.25.5/libsoup/soup-socket.c
===================================================================
--- libsoup-2.25.5.orig/libsoup/soup-socket.c	2009-02-11 09:36:58.000000000 +0100
+++ libsoup-2.25.5/libsoup/soup-socket.c	2009-02-11 09:39:05.000000000 +0100
@@ -1192,12 +1192,12 @@
  * @sock: the socket
  * @buffer: buffer to read into
  * @len: size of @buffer in bytes
- * @boundary: boundary to read until
- * @boundary_len: length of @boundary in bytes
+ * @ptrarray: Array of boundary strings to read up to
  * @nread: on return, the number of bytes read into @buffer
  * @got_boundary: on return, whether or not the data in @buffer
  * ends with the boundary string
  * @cancellable: a #GCancellable, or %NULL
+ * @bound_len: The returned length of the found boundary string
  * @error: error pointer
  *
  * Like soup_socket_read(), but reads no further than the first
@@ -1209,19 +1209,20 @@
  **/
 SoupSocketIOStatus
 soup_socket_read_until (SoupSocket *sock, gpointer buffer, gsize len,
-			gconstpointer boundary, gsize boundary_len,
+			GPtrArray *ptrarray,
 			gsize *nread, gboolean *got_boundary,
-			GCancellable *cancellable, GError **error)
+			GCancellable *cancellable, gint *bound_len, 
+			GError **error)
 {
 	SoupSocketPrivate *priv;
 	SoupSocketIOStatus status;
 	GByteArray *read_buf;
-	guint match_len, prev_len;
+	guint i, match_len, prev_len, max_len = 0;
 	guint8 *p, *end;
 
 	g_return_val_if_fail (SOUP_IS_SOCKET (sock), SOUP_SOCKET_ERROR);
 	g_return_val_if_fail (nread != NULL, SOUP_SOCKET_ERROR);
-	g_return_val_if_fail (len >= boundary_len, SOUP_SOCKET_ERROR);
+	g_return_val_if_fail (bound_len != NULL, SOUP_SOCKET_ERROR);
 
 	priv = SOUP_SOCKET_GET_PRIVATE (sock);
 
@@ -1229,11 +1230,20 @@
 
 	*got_boundary = FALSE;
 
+	/* Find out maximum boundary string length to search for */
+	for (i = 0; i < ptrarray->len; i++) {
+		gchar *tmp = g_ptr_array_index(ptrarray, i);
+		gint   tmplen = strlen(tmp);
+		if (tmplen > max_len)
+			max_len = tmplen;
+	}
+	
 	if (!priv->read_buf)
 		priv->read_buf = g_byte_array_new ();
 	read_buf = priv->read_buf;
 
-	if (read_buf->len < boundary_len) {
+	/* If not enough content in buffer get more */
+	if (read_buf->len < max_len) {
 		prev_len = read_buf->len;
 		g_byte_array_set_size (read_buf, len);
 		status = read_from_network (sock,
@@ -1249,12 +1259,22 @@
 
 	/* Scan for the boundary */
 	end = read_buf->data + read_buf->len;
-	for (p = read_buf->data; p <= end - boundary_len; p++) {
-		if (!memcmp (p, boundary, boundary_len)) {
-			p += boundary_len;
-			*got_boundary = TRUE;
-			break;
-		}
+	for (i = 0; i < ptrarray->len; i++) {
+		gchar *tmp = g_ptr_array_index(ptrarray, i);
+		gint   tmplen = strlen(tmp);
+		for (p = read_buf->data; p <= end - tmplen; p++) {
+			if (!memcmp (p, tmp, tmplen)) {
+				/* Special case handling */
+				if (*p == '\n' && *(p+1) == '\n')
+					*p = '\r';
+				p += tmplen;
+				*bound_len = tmplen;
+				*got_boundary = TRUE;
+				break;
+			}
+		}    
+		if (*got_boundary)
+		break;
 	}
 
 	/* Return everything up to 'p' (which is either just after the
Index: libsoup-2.25.5/libsoup/soup-socket.h
===================================================================
--- libsoup-2.25.5.orig/libsoup/soup-socket.h	2009-02-11 09:36:58.000000000 +0100
+++ libsoup-2.25.5/libsoup/soup-socket.h	2009-02-11 09:38:13.000000000 +0100
@@ -96,11 +96,11 @@
 SoupSocketIOStatus  soup_socket_read_until (SoupSocket         *sock,
 					    gpointer            buffer,
 					    gsize               len,
-					    gconstpointer       boundary,
-					    gsize               boundary_len,
+					    GPtrArray          *ptrarray,
 					    gsize              *nread,
 					    gboolean           *got_boundary,
 					    GCancellable       *cancellable,
+					    gint               *bound_len,
 					    GError            **error);
 
 SoupSocketIOStatus  soup_socket_write      (SoupSocket         *sock,
