wget: user-friendly fallback to http
authorLauri Kasanen <curaga@operamail.com>
Tue, 17 Dec 2013 18:03:41 +0000 (19:03 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 17 Dec 2013 18:09:43 +0000 (19:09 +0100)
GNU wget: wget google.com // ok
bb before: wget google.com // wget: not an http or ftp url

function                                             old     new   delta
parse_url                                            317     339     +22

Signed-off-by: Lauri Kasanen <curaga@operamail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
networking/wget.c

index cfbacecede849884335dbbf94125bdfa1cabdde7..d6c509edced27fad371301dda543780b1fd93427 100644 (file)
@@ -274,14 +274,21 @@ static void parse_url(const char *src_url, struct host_info *h)
        free(h->allocated);
        h->allocated = url = xstrdup(src_url);
 
-       if (strncmp(url, "http://", 7) == 0) {
-               h->port = bb_lookup_port("http", "tcp", 80);
-               h->host = url + 7;
-               h->is_ftp = 0;
-       } else if (strncmp(url, "ftp://", 6) == 0) {
+       if (strncmp(url, "ftp://", 6) == 0) {
                h->port = bb_lookup_port("ftp", "tcp", 21);
                h->host = url + 6;
                h->is_ftp = 1;
+       } else
+       if (strncmp(url, "http://", 7) == 0) {
+               h->host = url + 7;
+ http:
+               h->port = bb_lookup_port("http", "tcp", 80);
+               h->is_ftp = 0;
+       } else
+       if (!strstr(url, "//")) {
+               // GNU wget is user-friendly and falls back to http://
+               h->host = url;
+               goto http;
        } else
                bb_error_msg_and_die("not an http or ftp url: %s", sanitize_string(url));