]> sjero.net Git - wget/blobdiff - src/http.c
Parse content-length before using it. Fixes NTLM (#27192).
[wget] / src / http.c
index 311cb97289537c3bf10e3435f69a536acf88bb16..a469745c46360d52f921da96b3c57fed5b4b71c3 100644 (file)
@@ -1834,6 +1834,31 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy,
       print_server_response (resp, "  ");
     }
 
+  if (!opt.ignore_length
+      && resp_header_copy (resp, "Content-Length", hdrval, sizeof (hdrval)))
+    {
+      wgint parsed;
+      errno = 0;
+      parsed = str_to_wgint (hdrval, NULL, 10);
+      if (parsed == WGINT_MAX && errno == ERANGE)
+        {
+          /* Out of range.
+             #### If Content-Length is out of range, it most likely
+             means that the file is larger than 2G and that we're
+             compiled without LFS.  In that case we should probably
+             refuse to even attempt to download the file.  */
+          contlen = -1;
+        }
+      else if (parsed < 0)
+        {
+          /* Negative Content-Length; nonsensical, so we can't
+             assume any information about the content to receive. */
+          contlen = -1;
+        }
+      else
+        contlen = parsed;
+    }
+
   /* Check for keep-alive related responses. */
   if (!inhibit_keep_alive && contlen != -1)
     {
@@ -2038,31 +2063,6 @@ File %s already there; not retrieving.\n\n"), quote (hs->local_file));
         }
     }
 
-  if (!opt.ignore_length
-      && resp_header_copy (resp, "Content-Length", hdrval, sizeof (hdrval)))
-    {
-      wgint parsed;
-      errno = 0;
-      parsed = str_to_wgint (hdrval, NULL, 10);
-      if (parsed == WGINT_MAX && errno == ERANGE)
-        {
-          /* Out of range.
-             #### If Content-Length is out of range, it most likely
-             means that the file is larger than 2G and that we're
-             compiled without LFS.  In that case we should probably
-             refuse to even attempt to download the file.  */
-          contlen = -1;
-        }
-      else if (parsed < 0)
-        {
-          /* Negative Content-Length; nonsensical, so we can't
-             assume any information about the content to receive. */
-          contlen = -1;
-        }
-      else
-        contlen = parsed;
-    }
-
   request_free (req);
 
   hs->statcode = statcode;
@@ -2175,10 +2175,10 @@ File %s already there; not retrieving.\n\n"), quote (hs->local_file));
   else
     *dt &= ~TEXTCSS;
 
-  if (opt.html_extension)
+  if (opt.adjust_extension)
     {
       if (*dt & TEXTHTML)
-        /* -E / --html-extension / html_extension = on was specified,
+        /* -E / --adjust-extension / adjust_extension = on was specified,
            and this is a text/html file.  If some case-insensitive
            variation on ".htm[l]" isn't already the file's suffix,
            tack on ".html". */