]> git.saurik.com Git - apt.git/blobdiff - methods/http.cc
rename the 'universe' to 'scenario' to reflect the naming in the draft
[apt.git] / methods / http.cc
index 9fa74bffabff5362adaad277d6eec7d40e2650a4..dfc1619e3c4994c9dda537c2728c6722e9b8fd82 100644 (file)
@@ -553,8 +553,14 @@ bool ServerState::HeaderLine(string Line)
       // Evil servers return no version
       if (Line[4] == '/')
       {
-        if (sscanf(Line.c_str(),"HTTP/%u.%u %u%[^\n]",&Major,&Minor,
-                   &Result,Code) != 4)
+        int const elements = sscanf(Line.c_str(),"HTTP/%u.%u %u%[^\n]",&Major,&Minor,&Result,Code);
+        if (elements == 3)
+        {
+           Code[0] = '\0';
+           if (Debug == true)
+              clog << "HTTP server doesn't give Reason-Phrase for " << Result << std::endl;
+        }
+        else if (elements != 4)
            return _error->Error(_("The HTTP server sent an invalid reply header"));
       }
       else
@@ -1343,9 +1349,10 @@ bool HttpMethod::AutoDetectProxy()
    pid_t Process = ExecFork();
    if (Process == 0)
    {
+      close(Pipes[0]);
       dup2(Pipes[1],STDOUT_FILENO);
       SetCloseExec(STDOUT_FILENO,false);
-      
+
       const char *Args[2];
       Args[0] = AutoDetectProxyCmd.c_str();
       Args[1] = 0;
@@ -1355,10 +1362,18 @@ bool HttpMethod::AutoDetectProxy()
    }
    char buf[512];
    int InFd = Pipes[0];
-   if (read(InFd, buf, sizeof(buf)) < 0)
+   close(Pipes[1]);
+   int res = read(InFd, buf, sizeof(buf));
+   ExecWait(Process, "ProxyAutoDetect", true);
+
+   if (res < 0)
       return _error->Errno("read", "Failed to read");
-   ExecWait(Process, "ProxyAutoDetect");
-   
+   if (res == 0)
+      return _error->Warning("ProxyAutoDetect returned no data");
+
+   // add trailing \0
+   buf[res] = 0;
+
    if (Debug)
       clog << "auto detect command returned: '" << buf << "'" << endl;