]> git.saurik.com Git - apt.git/blobdiff - methods/http.cc
merged from lp:~mvo/apt/mvo
[apt.git] / methods / http.cc
index 3b210f6b612153fd5a433e784956b28c22ce6677..45804656d05842a9027af017e553f8cddb4121fd 100644 (file)
@@ -682,23 +682,25 @@ void HttpMethod::SendReq(FetchItem *Itm,CircleBuf &Out)
                 and a no-store directive for archives. */
       sprintf(Buf,"GET %s HTTP/1.1\r\nHost: %s\r\n",
              Itm->Uri.c_str(),ProperHost.c_str());
-      // only generate a cache control header if we actually want to 
-      // use a cache
-      if (_config->FindB("Acquire::http::No-Cache",false) == false)
+   }
+   // generate a cache control header (if needed)
+   if (_config->FindB("Acquire::http::No-Cache",false) == true) 
+   {
+      strcat(Buf,"Cache-Control: no-cache\r\nPragma: no-cache\r\n");
+   }
+   else
+   {
+      if (Itm->IndexFile == true) 
       {
-        if (Itm->IndexFile == true)
-           sprintf(Buf+strlen(Buf),"Cache-Control: max-age=%u\r\n",
-                   _config->FindI("Acquire::http::Max-Age",0));
-        else
-        {
-           if (_config->FindB("Acquire::http::No-Store",false) == true)
-              strcat(Buf,"Cache-Control: no-store\r\n");
-        }       
+        sprintf(Buf+strlen(Buf),"Cache-Control: max-age=%u\r\n",
+                _config->FindI("Acquire::http::Max-Age",0));
+      }
+      else
+      {
+        if (_config->FindB("Acquire::http::No-Store",false) == true)
+           strcat(Buf,"Cache-Control: no-store\r\n");
       }
    }
-   // generate a no-cache header if needed
-   if (_config->FindB("Acquire::http::No-Cache",false) == true)
-      strcat(Buf,"Cache-Control: no-cache\r\nPragma: no-cache\r\n");
 
    
    string Req = Buf;
@@ -731,7 +733,8 @@ 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: " + _config->Find("Acquire::http::User-Agent",
+               "Ubuntu APT-HTTP/1.3 ("VERSION")") + "\r\n\r\n";
    
    if (Debug == true)
       cerr << Req << endl;
@@ -955,6 +958,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;
@@ -1031,7 +1037,7 @@ void HttpMethod::SigTerm(int)
    depth. */
 bool HttpMethod::Fetch(FetchItem *)
 {
-   if (Server == 0)
+   if (Server == 0) 
       return true;
 
    // Queue the requests
@@ -1321,15 +1327,4 @@ int HttpMethod::Loop()
 }
                                                                        /*}}}*/
 
-int main()
-{
-   setlocale(LC_ALL, "");
-   // ignore SIGPIPE, this can happen on write() if the socket
-   // closes the connection (this is dealt with via ServerDie())
-   signal(SIGPIPE, SIG_IGN);
-
-   HttpMethod Mth;
-   return Mth.Loop();
-}
-