summaryrefslogtreecommitdiff
path: root/methods/http.cc
diff options
context:
space:
mode:
Diffstat (limited to 'methods/http.cc')
-rw-r--r--methods/http.cc70
1 files changed, 7 insertions, 63 deletions
diff --git a/methods/http.cc b/methods/http.cc
index 916fa464f..b076e59cc 100644
--- a/methods/http.cc
+++ b/methods/http.cc
@@ -34,6 +34,7 @@
#include <apt-pkg/hashes.h>
#include <apt-pkg/netrc.h>
#include <apt-pkg/strutl.h>
+#include <apt-pkg/proxy.h>
#include <stddef.h>
#include <stdlib.h>
@@ -308,6 +309,7 @@ bool HttpServerState::Open()
Persistent = true;
// Determine the proxy setting
+ AutoDetectProxy(ServerName);
string SpecificProxy = _config->Find("Acquire::http::Proxy::" + ServerName.Host);
if (!SpecificProxy.empty())
{
@@ -653,9 +655,11 @@ bool HttpServerState::Go(bool ToFile, FileFd * const File)
return _error->Errno("write",_("Error writing to output file"));
}
- if (ExpectedSize > 0 && In.TotalWriten > ExpectedSize)
+ if (ExpectedSize > 0 && File && File->Tell() > ExpectedSize)
+ {
return _error->Error("Writing more data than expected (%llu > %llu)",
- In.TotalWriten, ExpectedSize);
+ File->Tell(), ExpectedSize);
+ }
// Handle commands from APT
if (FD_ISSET(STDIN_FILENO,&rfds))
@@ -752,7 +756,7 @@ void HttpMethod::SendReq(FetchItem *Itm)
Req << "\r\n";
if (Debug == true)
- cerr << Req << endl;
+ cerr << Req.str() << endl;
Server->WriteResponse(Req.str());
}
@@ -770,66 +774,6 @@ bool HttpMethod::Configuration(string Message)
PipelineDepth);
Debug = _config->FindB("Debug::Acquire::http",false);
- // Get the proxy to use
- AutoDetectProxy();
-
- return true;
-}
- /*}}}*/
-// HttpMethod::AutoDetectProxy - auto detect proxy /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-bool HttpMethod::AutoDetectProxy()
-{
- // option is "Acquire::http::Proxy-Auto-Detect" but we allow the old
- // name without the dash ("-")
- AutoDetectProxyCmd = _config->Find("Acquire::http::Proxy-Auto-Detect",
- _config->Find("Acquire::http::ProxyAutoDetect"));
-
- if (AutoDetectProxyCmd.empty())
- return true;
-
- if (Debug)
- clog << "Using auto proxy detect command: " << AutoDetectProxyCmd << endl;
-
- int Pipes[2] = {-1,-1};
- if (pipe(Pipes) != 0)
- return _error->Errno("pipe", "Failed to create Pipe");
-
- 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;
- execv(Args[0],(char **)Args);
- cerr << "Failed to exec method " << Args[0] << endl;
- _exit(100);
- }
- char buf[512];
- int InFd = Pipes[0];
- close(Pipes[1]);
- int res = read(InFd, buf, sizeof(buf)-1);
- ExecWait(Process, "ProxyAutoDetect", true);
-
- if (res < 0)
- return _error->Errno("read", "Failed to read");
- 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;
-
- if (strstr(buf, "http://") == buf)
- _config->Set("Acquire::http::proxy", _strstrip(buf));
-
return true;
}
/*}}}*/