blob: c5e471a530a766516034afe1d49606aee07cc3b1 [file] [log] [blame]
From bb23caf7db4e9112089e1502aa8c106178095e7e Mon Sep 17 00:00:00 2001
From: Carlos Garcia Campos <cgarcia@igalia.com>
Date: Tue, 21 Mar 2017 14:19:46 +0100
Subject: [PATCH] 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 | 34 ++++++++++++++++++++--------------
1 file changed, 20 insertions(+), 14 deletions(-)
diff --git a/libsoup/soup-message-io.c b/libsoup/soup-message-io.c
index e893ec2a..ea02b1e3 100644
--- a/libsoup/soup-message-io.c
+++ b/libsoup/soup-message-io.c
@@ -229,12 +229,16 @@ read_headers (SoupMessage *msg, gboolean blocking,
cancellable, error);
io->read_header_buf->len = old_len + MAX (nread, 0);
if (nread == 0) {
- soup_message_set_status (msg, SOUP_STATUS_MALFORMED);
- g_set_error_literal (error, G_IO_ERROR,
- G_IO_ERROR_PARTIAL_INPUT,
- _("Connection terminated unexpectedly"));
+ if (io->read_header_buf->len == 0) {
+ soup_message_set_status (msg, SOUP_STATUS_MALFORMED);
+ g_set_error_literal (error, G_IO_ERROR,
+ G_IO_ERROR_PARTIAL_INPUT,
+ _("Connection terminated unexpectedly"));
+ return FALSE;
+ }
+ break;
}
- if (nread <= 0)
+ if (nread < 0)
return FALSE;
if (got_lf) {
@@ -251,15 +255,17 @@ read_headers (SoupMessage *msg, gboolean blocking,
}
}
- /* 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;
+ if (got_lf) {
+ /* 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;
--
2.11.0