summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Garcia Campos <cgarcia@igalia.com>2018-01-03 08:55:53 +0100
committerCarlos Garcia Campos <carlosgc@gnome.org>2018-01-09 11:52:04 +0100
commitc60d7a851d3e3ac084bd5010656990c6a6a71c6b (patch)
treeabf8bd6ffea9e917de1851aeb928948d1542b119
parent87eefb31bf582fe83130afb75f4b6723b874936f (diff)
downloadlibsoup-c60d7a851d3e3ac084bd5010656990c6a6a71c6b.tar.gz
soup-headers: accept any 3 digit number as message status code
The HTTP RFC says that status code is extensible, but the category must be known by the client. However, popular websites like linkedin use invalid status codes such as 999, and all the major browsers handle that correctly. There are also WPT tests checking status codes greater than 599 in XMLHTTPRequests. So, let's parse the status code, only failing if it's not a 3 digit number and letting the user handle any other particular case. https://bugzilla.gnome.org/show_bug.cgi?id=792124
-rw-r--r--libsoup/soup-headers.c2
-rw-r--r--libsoup/soup-message.c2
-rw-r--r--tests/header-parsing.c12
3 files changed, 12 insertions, 4 deletions
diff --git a/libsoup/soup-headers.c b/libsoup/soup-headers.c
index 1c8900ec..271d2a63 100644
--- a/libsoup/soup-headers.c
+++ b/libsoup/soup-headers.c
@@ -323,7 +323,7 @@ soup_headers_parse_status_line (const char *status_line,
if (code_end != code_start + 3)
return FALSE;
code = atoi (code_start);
- if (code < 100 || code > 599)
+ if (code < 100 || code > 999)
return FALSE;
if (status_code)
*status_code = code;
diff --git a/libsoup/soup-message.c b/libsoup/soup-message.c
index 6287ac14..e4d78476 100644
--- a/libsoup/soup-message.c
+++ b/libsoup/soup-message.c
@@ -766,7 +766,7 @@ soup_message_class_init (SoupMessageClass *message_class)
g_param_spec_uint (SOUP_MESSAGE_STATUS_CODE,
"Status code",
"The HTTP response status code",
- 0, 599, 0,
+ 0, 999, 0,
G_PARAM_READWRITE));
/**
* SOUP_MESSAGE_REASON_PHRASE:
diff --git a/tests/header-parsing.c b/tests/header-parsing.c
index c8968793..9cf06cee 100644
--- a/tests/header-parsing.c
+++ b/tests/header-parsing.c
@@ -517,6 +517,14 @@ static struct ResponseTest {
}
},
+ { "Response w/ unknown status code", NULL,
+ "HTTP/1.1 999 Request denied\r\nFoo: bar\r\n", -1,
+ SOUP_HTTP_1_1, 999, "Request denied",
+ { { "Foo", "bar" },
+ { NULL }
+ }
+ },
+
{ "Connection header on HTTP/1.0 message", NULL,
"HTTP/1.0 200 ok\r\nFoo: bar\r\nConnection: Bar\r\nBar: quux\r\n", -1,
SOUP_HTTP_1_0, SOUP_STATUS_OK, "ok",
@@ -704,8 +712,8 @@ static struct ResponseTest {
{ { NULL } }
},
- { "Status code > 599", NULL,
- "HTTP/1.1 600 OK\r\nFoo: bar\r\n", -1,
+ { "Status code > 999", NULL,
+ "HTTP/1.1 1000 OK\r\nFoo: bar\r\n", -1,
-1, 0, NULL,
{ { NULL } }
},