]> git.saurik.com Git - apt.git/blobdiff - methods/http.cc
* Simplified HttpMethod::Fetch on http.cc removing Tail variable;
[apt.git] / methods / http.cc
index 3c2d8a36f455be9189eac218bf2a8affdd803f4f..6aa4261ff37347cbf375d08666ec4f6569f852c3 100644 (file)
@@ -38,7 +38,6 @@
 #include <stdio.h>
 #include <errno.h>
 #include <string.h>
-#include <iostream>
 #include <apti18n.h>
 
 // Internet stuff
@@ -715,7 +714,7 @@ void HttpMethod::SendReq(FetchItem *Itm,CircleBuf &Out)
       Req += string("Authorization: Basic ") + 
           Base64Encode(Uri.User + ":" + Uri.Password) + "\r\n";
    
-   Req += "User-Agent: Debian APT-HTTP/1.3 ("VERSION")\r\n\r\n";
+   Req += "User-Agent: Ubuntu APT-HTTP/1.3 ("VERSION")\r\n\r\n";
    
    if (Debug == true)
       cerr << Req << endl;
@@ -916,6 +915,9 @@ int HttpMethod::DealWithHeaders(FetchResult &Res,ServerState *Srv)
       failure */
    if (Srv->Result < 200 || Srv->Result >= 300)
    {
+      char err[255];
+      snprintf(err,sizeof(err)-1,"HttpError%i",Srv->Result);
+      SetFailReason(err);
       _error->Error("%u %s",Srv->Result,Srv->Code);
       if (Srv->HaveContent == true)
         return 4;
@@ -991,12 +993,11 @@ void HttpMethod::SigTerm(int)
    depth. */
 bool HttpMethod::Fetch(FetchItem *)
 {
-   if (Server == 0)
+   if (Server == 0) 
       return true;
 
    // Queue the requests
    int Depth = -1;
-   bool Tail = false;
    for (FetchItem *I = Queue; I != 0 && Depth < (signed)PipelineDepth; 
        I = I->Next, Depth++)
    {
@@ -1008,8 +1009,6 @@ bool HttpMethod::Fetch(FetchItem *)
       if (Server->Comp(I->Uri) == false)
         break;
       if (QueueBack == I)
-        Tail = true;
-      if (Tail == true)
       {
         QueueBack = I->Next;
         SendReq(I,Server->Out);
@@ -1071,7 +1070,6 @@ int HttpMethod::Loop()
         delete Server;
         Server = new ServerState(Queue->Uri,this);
       }
-      
       /* If the server has explicitly said this is the last connection
          then we pre-emptively shut down the pipeline and tear down 
         the connection. This will speed up HTTP/1.0 servers a tad
@@ -1168,8 +1166,24 @@ int HttpMethod::Loop()
               URIDone(Res);
            }
            else
-              Fail(true);
-           
+           {
+              if (Server->ServerFd == -1)
+              {
+                 FailCounter++;
+                 _error->Discard();
+                 Server->Close();
+                 
+                 if (FailCounter >= 2)
+                 {
+                    Fail(_("Connection failed"),true);
+                    FailCounter = 0;
+                 }
+                 
+                 QueueBack = Queue;
+              }
+              else
+                 Fail(true);
+           }
            break;
         }
         
@@ -1224,13 +1238,5 @@ int HttpMethod::Loop()
 }
                                                                        /*}}}*/
 
-int main()
-{
-   setlocale(LC_ALL, "");
-
-   HttpMethod Mth;
-   
-   return Mth.Loop();
-}