bug-wget
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-wget] BUG #26775


From: Filip M. Nowak
Subject: [Bug-wget] BUG #26775
Date: Sat, 13 Jun 2009 02:18:05 +0200
User-agent: Mozilla-Thunderbird 2.0.0.19 (X11/20090103)

Hi there.

I'm sending you patch as attachment. It resolves issue with saving cookies when 401 error occurs. I'm investigating need of modification wget behaviour in case of another errors/responses, but it's probably bad idea - for example for 50X codes. As you can see, piece of code responsible for cookie handling executed after proper authorization was moved up - when wget catches 401 it's executed. I tested it on my webserver and it seems to work nice.
What do you think about proposed resolution?

--
Kind regards,
Filip M. Nowak
--- src/http.c.orig     2009-06-13 02:05:07.875446740 +0200
+++ src/http.c  2009-06-13 02:03:21.135447383 +0200
@@ -1953,6 +1953,35 @@
 
   if (statcode == HTTP_STATUS_UNAUTHORIZED)
     {
+   /* Handle (possibly multiple instances of) the Set-Cookie header. */
+   if (opt.cookies)
+     {
+       int scpos;
+       const char *scbeg, *scend;
+       /* The jar should have been created by now. */
+       assert (wget_cookie_jar != NULL);
+       for (scpos = 0;
+            (scpos = resp_header_locate (resp, "Set-Cookie", scpos,
+                                         &scbeg, &scend)) != -1;
+            ++scpos)
+         {
+           char *set_cookie; BOUNDED_TO_ALLOCA (scbeg, scend, set_cookie);
+           cookie_handle_set_cookie (wget_cookie_jar, u->host, u->port,
+                                     u->path, set_cookie);
+         }
+     }
+
+   if (resp_header_copy (resp, "Content-Range", hdrval, sizeof (hdrval)))
+     {
+       wgint first_byte_pos, last_byte_pos, entity_length;
+       if (parse_content_range (hdrval, &first_byte_pos, &last_byte_pos,
+                                &entity_length))
+         {
+           contrange = first_byte_pos;
+           contlen = last_byte_pos - first_byte_pos + 1;
+         }
+     }
+
       /* Authorization is required.  */
       if (keep_alive && !head_only && skip_short_body (sock, contlen))
         CLOSE_FINISH (sock);
@@ -2047,36 +2076,6 @@
   hs->newloc = resp_header_strdup (resp, "Location");
   hs->remote_time = resp_header_strdup (resp, "Last-Modified");
 
-  /* Handle (possibly multiple instances of) the Set-Cookie header. */
-  if (opt.cookies)
-    {
-      int scpos;
-      const char *scbeg, *scend;
-      /* The jar should have been created by now. */
-      assert (wget_cookie_jar != NULL);
-      for (scpos = 0;
-           (scpos = resp_header_locate (resp, "Set-Cookie", scpos,
-                                        &scbeg, &scend)) != -1;
-           ++scpos)
-        {
-          char *set_cookie; BOUNDED_TO_ALLOCA (scbeg, scend, set_cookie);
-          cookie_handle_set_cookie (wget_cookie_jar, u->host, u->port,
-                                    u->path, set_cookie);
-        }
-    }
-
-  if (resp_header_copy (resp, "Content-Range", hdrval, sizeof (hdrval)))
-    {
-      wgint first_byte_pos, last_byte_pos, entity_length;
-      if (parse_content_range (hdrval, &first_byte_pos, &last_byte_pos,
-                               &entity_length))
-        {
-          contrange = first_byte_pos;
-          contlen = last_byte_pos - first_byte_pos + 1;
-        }
-    }
-  resp_free (resp);
-
   /* 20x responses are counted among successful by default.  */
   if (H_20X (statcode))
     *dt |= RETROKF;

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]