[libsoup] soup-message-io: Do not fail when there's no empty line after headers



commit 2177c522a46809be3eee15bf0864b8491c67467d
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Tue Mar 21 14:19:46 2017 +0100

    soup-message-io: Do not fail when there's no empty line after headers
    
    The spec says there should be an empty line (\r\n) between the response
    headers and the body. However, some servers don't include the empty line
    when the response doesn't have a body. This is causing several WebKit
    tests to fail, because some of the imported w3c tests do not include
    that empty line. Those tests pass in firefox, chromium and safari, so at
    least those other browsers allow that.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=780352

 libsoup/soup-message-io.c |   21 ++++++++-------------
 1 files changed, 8 insertions(+), 13 deletions(-)
---
diff --git a/libsoup/soup-message-io.c b/libsoup/soup-message-io.c
index e893ec2..fb505fa 100644
--- a/libsoup/soup-message-io.c
+++ b/libsoup/soup-message-io.c
@@ -229,6 +229,8 @@ read_headers (SoupMessage *msg, gboolean blocking,
                                                            cancellable, error);
                io->read_header_buf->len = old_len + MAX (nread, 0);
                if (nread == 0) {
+                       if (io->read_header_buf->len > 0)
+                               break;
                        soup_message_set_status (msg, SOUP_STATUS_MALFORMED);
                        g_set_error_literal (error, G_IO_ERROR,
                                             G_IO_ERROR_PARTIAL_INPUT,
@@ -241,27 +243,20 @@ read_headers (SoupMessage *msg, gboolean blocking,
                        if (nread == 1 && old_len >= 2 &&
                            !strncmp ((char *)io->read_header_buf->data +
                                      io->read_header_buf->len - 2,
-                                     "\n\n", 2))
+                                     "\n\n", 2)) {
+                               io->read_header_buf->len--;
                                break;
-                       else if (nread == 2 && old_len >= 3 &&
+                       } else if (nread == 2 && old_len >= 3 &&
                                 !strncmp ((char *)io->read_header_buf->data +
                                           io->read_header_buf->len - 3,
-                                          "\n\r\n", 3))
+                                          "\n\r\n", 3)) {
+                               io->read_header_buf->len -= 2;
                                break;
+                       }
                }
        }
 
-       /* We need to "rewind" io->read_header_buf back one line.
-        * That SHOULD be two characters (CR LF), but if the
-        * web server was stupid, it might only be one.
-        */
-       if (io->read_header_buf->len < 3 ||
-           io->read_header_buf->data[io->read_header_buf->len - 2] == '\n')
-               io->read_header_buf->len--;
-       else
-               io->read_header_buf->len -= 2;
        io->read_header_buf->data[io->read_header_buf->len] = '\0';
-
        return TRUE;
 }
 


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