Ver código fonte

Location header in redirects should be absolute URI, but some
servers just send an absolute path so still deal with it properly

David Kalnischkies 15 anos atrás
pai
commit
4992469e45
2 arquivos alterados com 20 adições e 2 exclusões
  1. 3 1
      debian/changelog
  2. 17 1
      methods/http.cc

+ 3 - 1
debian/changelog

@@ -48,8 +48,10 @@ apt (0.8.14.2) UNRELEASED; urgency=low
   * methods/http.cc:
     - add config option to ignore a closed stdin to be able to easily
       use the method as a simple standalone downloader
+    - Location header in redirects should be absolute URI, but some
+      servers just send an absolute path so still deal with it properly
 
- -- David Kalnischkies <kalnischkies@gmail.com>  Wed, 27 Apr 2011 10:30:47 +0200
+ -- David Kalnischkies <kalnischkies@gmail.com>  Wed, 27 Apr 2011 17:37:58 +0200
 
 apt (0.8.14.1) unstable; urgency=low
 

+ 17 - 1
methods/http.cc

@@ -948,7 +948,23 @@ HttpMethod::DealWithHeaders(FetchResult &Res,ServerState *Srv)
            && Srv->Result != 304    // Not Modified
            && Srv->Result != 306))  // (Not part of HTTP/1.1, reserved)
    {
-      if (!Srv->Location.empty())
+      if (Srv->Location.empty() == true);
+      else if (Srv->Location[0] == '/' && Queue->Uri.empty() == false)
+      {
+	 URI Uri = Queue->Uri;
+	 if (Uri.Host.empty() == false)
+	 {
+	    if (Uri.Port != 0)
+	       strprintf(NextURI, "http://%s:%u", Uri.Host.c_str(), Uri.Port);
+	    else
+	       NextURI = "http://" + Uri.Host;
+	 }
+	 else
+	    NextURI.clear();
+	 NextURI.append(Srv->Location);
+	 return TRY_AGAIN_OR_REDIRECT;
+      }
+      else
       {
          NextURI = Srv->Location;
          return TRY_AGAIN_OR_REDIRECT;