Deal with Shoutcast servers, which return "ICY 200 OK", but are otherwise
authorDan Winship <danw@src.gnome.org>
Wed, 16 Jan 2008 22:00:32 +0000 (22:00 +0000)
committerDan Winship <danw@src.gnome.org>
Wed, 16 Jan 2008 22:00:32 +0000 (22:00 +0000)
* libsoup/soup-headers.c (soup_headers_parse_status_line): Deal
with Shoutcast servers, which return "ICY 200 OK", but are
otherwise straight HTTP/1.0. #502325, Wouter Cloetens.

* tests/header-parsing.c (resptests): add a test for it

svn path=/trunk/; revision=1046

ChangeLog
libsoup/soup-headers.c
tests/header-parsing.c

index 6482fc2..f5d6614 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2008-01-16  Dan Winship  <danw@gnome.org>
 
+       * libsoup/soup-headers.c (soup_headers_parse_status_line): Deal
+       with Shoutcast servers, which return "ICY 200 OK", but are
+       otherwise straight HTTP/1.0. #502325, Wouter Cloetens.
+
+       * tests/header-parsing.c (resptests): add a test for it
+
+2008-01-16  Dan Winship  <danw@gnome.org>
+
        * libsoup/soup-auth-manager.c (authorize_handler, etc): Allow the
        session authenticate signal to be handled asynchronously, by
        pausing the message and then authenticating the auth later.
index 3fe3993..05be497 100644 (file)
@@ -229,19 +229,23 @@ soup_headers_parse_status_line (const char       *status_line,
        const char *code_start, *code_end, *phrase_start, *phrase_end;
        char *p;
 
-       if (strncmp (status_line, "HTTP/", 5) != 0 ||
-           !g_ascii_isdigit (status_line[5]))
-               return FALSE;
-       major_version = strtoul (status_line + 5, &p, 10);
-       if (*p != '.' || !g_ascii_isdigit (p[1]))
-               return FALSE;
-       minor_version = strtoul (p + 1, &p, 10);
-       if (major_version != 1)
-               return FALSE;
-       if (minor_version < 0 || minor_version > 1)
-               return FALSE;
-       if (ver)
-               *ver = (minor_version == 0) ? SOUP_HTTP_1_0 : SOUP_HTTP_1_1;
+       if (strncmp (status_line, "HTTP/", 5) == 0 &&
+           g_ascii_isdigit (status_line[5])) {
+               major_version = strtoul (status_line + 5, &p, 10);
+               if (*p != '.' || !g_ascii_isdigit (p[1]))
+                       return FALSE;
+               minor_version = strtoul (p + 1, &p, 10);
+               if (major_version != 1)
+                       return FALSE;
+               if (minor_version < 0 || minor_version > 1)
+                       return FALSE;
+               if (ver)
+                       *ver = (minor_version == 0) ? SOUP_HTTP_1_0 : SOUP_HTTP_1_1;
+       } else if (!strncmp (status_line, "ICY", 3)) {
+               /* Shoutcast not-quite-HTTP format */
+               *ver = SOUP_HTTP_1_0;
+               p = (char *)status_line + 3;
+       }
 
        code_start = p;
        while (*code_start == ' ' || *code_start == '\t')
index 63fcae3..0f92c02 100644 (file)
@@ -443,6 +443,14 @@ struct ResponseTest {
          }
        },
 
+       { "Shoutcast server not-quite-HTTP",
+         "ICY 200 OK\r\nFoo: bar\r\n", -1,
+         SOUP_HTTP_1_0, SOUP_STATUS_OK, "OK",
+         { { "Foo", "bar" },
+           { NULL }
+         }
+       },
+
        /*************************/
        /*** INVALID RESPONSES ***/
        /*************************/