[libsoup] soup-message-io: deal with stupid servers that do chunked encoding wrong



commit 5beca05b68f92b69bb47ade94fb4857c5ccf8b76
Author: Dan Winship <danw gnome org>
Date:   Tue Nov 9 13:22:25 2010 -0500

    soup-message-io: deal with stupid servers that do chunked encoding wrong
    
    Some servers fail to send the final 0-length chunk when allegedly doing
    chunked encoding. Browsers cope. Now we do too.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=629160

 libsoup/soup-message-io.c |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)
---
diff --git a/libsoup/soup-message-io.c b/libsoup/soup-message-io.c
index f4f4c96..815bc0b 100644
--- a/libsoup/soup-message-io.c
+++ b/libsoup/soup-message-io.c
@@ -309,8 +309,26 @@ read_metadata (SoupMessage *msg, gboolean to_blank)
 			g_byte_array_append (io->read_meta_buf, read_buf, nread);
 			break;
 
-		case SOUP_SOCKET_ERROR:
 		case SOUP_SOCKET_EOF:
+			/* More lame server handling... deal with
+			 * servers that don't send the final chunk.
+			 */
+			if (io->read_state == SOUP_MESSAGE_IO_STATE_CHUNK_SIZE &&
+			    io->read_meta_buf->len == 0) {
+				g_byte_array_append (io->read_meta_buf,
+						     (guchar *)"0\r\n", 3);
+				got_lf = TRUE;
+				break;
+			} else if (io->read_state == SOUP_MESSAGE_IO_STATE_TRAILERS &&
+				   io->read_meta_buf->len == 0) {
+				g_byte_array_append (io->read_meta_buf,
+						     (guchar *)"\r\n", 2);
+				got_lf = TRUE;
+				break;
+			}
+			/* else fall through */
+
+		case SOUP_SOCKET_ERROR:
 			io_error (io->sock, msg, error);
 			return FALSE;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]