summaryrefslogtreecommitdiff
path: root/methods/http.cc
diff options
context:
space:
mode:
Diffstat (limited to 'methods/http.cc')
-rw-r--r--methods/http.cc50
1 files changed, 41 insertions, 9 deletions
diff --git a/methods/http.cc b/methods/http.cc
index 25e31de9a..13f9cbe06 100644
--- a/methods/http.cc
+++ b/methods/http.cc
@@ -778,9 +778,10 @@ bool HttpMethod::Go(bool ToFile,ServerState *Srv)
if (Srv->In.WriteSpace() == true && ToFile == true && FileFD != -1)
FD_SET(FileFD,&wfds);
-
+
// Add stdin
- FD_SET(STDIN_FILENO,&rfds);
+ if (_config->FindB("Acquire::http::DependOnSTDIN", true) == true)
+ FD_SET(STDIN_FILENO,&rfds);
// Figure out the max fd
int MaxFd = FileFD;
@@ -947,9 +948,25 @@ HttpMethod::DealWithHeaders(FetchResult &Res,ServerState *Srv)
&& Srv->Result != 304 // Not Modified
&& Srv->Result != 306)) // (Not part of HTTP/1.1, reserved)
{
- if (!Srv->Location.empty())
+ if (Srv->Location.empty() == true);
+ else if (Srv->Location[0] == '/' && Queue->Uri.empty() == false)
+ {
+ URI Uri = Queue->Uri;
+ if (Uri.Host.empty() == false)
+ {
+ if (Uri.Port != 0)
+ strprintf(NextURI, "http://%s:%u", Uri.Host.c_str(), Uri.Port);
+ else
+ NextURI = "http://" + Uri.Host;
+ }
+ else
+ NextURI.clear();
+ NextURI.append(DeQuoteString(Srv->Location));
+ return TRY_AGAIN_OR_REDIRECT;
+ }
+ else
{
- NextURI = Srv->Location;
+ NextURI = DeQuoteString(Srv->Location);
return TRY_AGAIN_OR_REDIRECT;
}
/* else pass through for error message */
@@ -1113,7 +1130,13 @@ int HttpMethod::Loop()
do a WaitFd above.. Otherwise the FD is closed. */
int Result = Run(true);
if (Result != -1 && (Result != 0 || Queue == 0))
- return 100;
+ {
+ if(FailReason.empty() == false ||
+ _config->FindB("Acquire::http::DependOnSTDIN", true) == true)
+ return 100;
+ else
+ return 0;
+ }
if (Queue == 0)
continue;
@@ -1349,9 +1372,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;
@@ -1361,10 +1385,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;