summaryrefslogtreecommitdiff
path: root/methods/http.cc
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2010-02-17 22:40:05 +0100
committerMichael Vogt <michael.vogt@ubuntu.com>2010-02-17 22:40:05 +0100
commit9fcbe2047293f8ef703439264ed3d35701f51638 (patch)
tree5669db5c2fd2caf7274ff751f9e6a22311f09273 /methods/http.cc
parent424d785b672f80a0f1a5b6ab4a858c48f4c49bfd (diff)
parent762d7367f5f74f877ec75986e19fc9d46eef5164 (diff)
merged from the mvo branch
Diffstat (limited to 'methods/http.cc')
-rw-r--r--methods/http.cc49
1 files changed, 48 insertions, 1 deletions
diff --git a/methods/http.cc b/methods/http.cc
index 45804656d..904030e0a 100644
--- a/methods/http.cc
+++ b/methods/http.cc
@@ -1076,7 +1076,11 @@ bool HttpMethod::Configuration(string Message)
PipelineDepth = _config->FindI("Acquire::http::Pipeline-Depth",
PipelineDepth);
Debug = _config->FindB("Debug::Acquire::http",false);
-
+ AutoDetectProxyCmd = _config->Find("Acquire::http::ProxyAutoDetect");
+
+ // Get the proxy to use
+ AutoDetectProxy();
+
return true;
}
/*}}}*/
@@ -1326,5 +1330,48 @@ int HttpMethod::Loop()
return 0;
}
/*}}}*/
+// HttpMethod::AutoDetectProxy - auto detect proxy /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool HttpMethod::AutoDetectProxy()
+{
+ 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)
+ {
+ 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];
+ if (read(InFd, buf, sizeof(buf)) < 0)
+ return _error->Errno("read", "Failed to read");
+ ExecWait(Process, "ProxyAutoDetect");
+
+ if (Debug)
+ clog << "auto detect command returned: '" << buf << "'" << endl;
+
+ if (strstr(buf, "http://") == buf)
+ _config->Set("Acquire::http::proxy", _strstrip(buf));
+
+ return true;
+}
+ /*}}}*/