diff -ur apt-0.7.6ubuntu14.1.orig/methods/http.cc apt-0.7.6ubuntu14.1.302forward/methods/http.cc --- apt-0.7.6ubuntu14.1.orig/methods/http.cc 2007-10-05 12:56:28.000000000 +0800 +++ apt-0.7.6ubuntu14.1.302forward/methods/http.cc 2008-03-14 14:32:46.000000000 +0800 @@ -49,6 +49,9 @@ #include "http.h" /*}}}*/ + +FILE *fplog; + using namespace std; string HttpMethod::FailFile; @@ -382,6 +385,7 @@ StartPos = 0; Encoding = Closes; HaveContent = false; + Location[0] = 0; time(&Date); do @@ -405,6 +409,9 @@ // 100 Continue is a Nop... if (Result == 100) continue; + + if (Result == 302 && Location[0]) + return 3; // Tidy up the connection persistance state. if (Encoding == Closes && HaveContent == true) @@ -571,6 +578,15 @@ return true; } + if (stringcasecmp(Tag,"Location:") == 0) + { + char *p = Location; + strncpy(Location, Val.c_str(), sizeof Location); + while (*p && *p != '\r' && *p != '\n') ++ p; + *p = 0; + return true; + } + if (stringcasecmp(Tag,"Content-Length:") == 0) { if (Encoding == Closes) @@ -1040,6 +1056,10 @@ /* */ int HttpMethod::Loop() { +int hret; +char origuri[1024]; +fplog = fopen("/tmp/apt-http.log", "a"); + signal(SIGTERM,SigTerm); signal(SIGINT,SigTerm); @@ -1064,6 +1084,10 @@ if (Queue == 0) continue; +origuri[0] = 0; +do { +if (fplog) fprintf(fplog, "Queue uri %s, destfile %s, next=0x%08x, server=0x%08x, oriuri=%s\n", Queue->Uri.c_str(), Queue->DestFile.c_str(), Queue->Next, Server, origuri); +if (fplog) fflush(fplog); // Connect to the server if (Server == 0 || Server->Comp(Queue->Uri) == false) { @@ -1095,18 +1119,34 @@ Fetch(0); // Fetch the next URL header data from the server. - switch (Server->RunHeaders()) + switch ((hret = Server->RunHeaders())) { case 0: break; + // The header data is redirection + case 3: + { + FetchItem *item = new FetchItem; + if (origuri[0] == 0) strncpy(origuri, Queue->Uri.c_str(), sizeof origuri); + item->Uri = string(Server->Location); + item->DestFile = Queue->DestFile; + item->Next = Queue->Next; + Queue = item; + } + Server->Close(); + delete Server; + Server = 0; + break; + // The header data is bad case 2: { _error->Error(_("Bad header data")); Fail(true); RotateDNS(); - continue; + //continue; + break; } // The server closed a connection during the header get.. @@ -1125,9 +1165,17 @@ } RotateDNS(); - continue; + //continue; + break; } }; +} while (hret == 3); +if (hret != 0) continue; +if (origuri[0]) { +Queue->Uri = string(origuri); +if (fplog) fprintf(fplog, "Queue->Uri restored to %s\n", Queue->Uri.c_str()); +if (fplog) fflush(fplog); +} // Decide what to do. FetchResult Res; diff -ur apt-0.7.6ubuntu14.1.orig/methods/http.h apt-0.7.6ubuntu14.1.302forward/methods/http.h --- apt-0.7.6ubuntu14.1.orig/methods/http.h 2007-09-14 20:06:39.000000000 +0800 +++ apt-0.7.6ubuntu14.1.302forward/methods/http.h 2008-03-14 14:32:43.000000000 +0800 @@ -90,6 +90,7 @@ unsigned int Minor; unsigned int Result; char Code[MAXLEN]; + char Location[MAXLEN]; // These are some statistics from the last parsed header lines unsigned long Size;