// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: http.cc,v 1.4 1998/11/05 07:21:48 jgg Exp $
+// $Id: http.cc,v 1.9 1998/12/05 04:19:05 jgg Exp $
/* ######################################################################
HTTP Aquire Method - This is the HTTP aquire method for APT.
Out.Reset();
// Determine the proxy setting
- string DefProxy = _config->Find("Acquire::http::Proxy",getenv("http_proxy"));
- string SpecificProxy = _config->Find("Acquire::http::Proxy::" + ServerName.Host);
- if (SpecificProxy.empty() == false)
+ if (getenv("http_proxy") == 0)
{
- if (SpecificProxy == "DIRECT")
- Proxy = "";
+ string DefProxy = _config->Find("Acquire::http::Proxy");
+ string SpecificProxy = _config->Find("Acquire::http::Proxy::" + ServerName.Host);
+ if (SpecificProxy.empty() == false)
+ {
+ if (SpecificProxy == "DIRECT")
+ Proxy = "";
+ else
+ Proxy = SpecificProxy;
+ }
else
- Proxy = SpecificProxy;
- }
+ Proxy = DefProxy;
+ }
else
- Proxy = DefProxy;
-
+ Proxy = getenv("http_proxy");
+
// Determine what host and port to use based on the proxy settings
int Port = 80;
string Host;
Req += string("Proxy-Authorization: Basic ") + Base64Encode(ProxyAuth) + "\r\n";*/
Req += "User-Agent: Debian APT-HTTP/1.2\r\n\r\n";
-// cout << Req << endl;
+// cerr << Req << endl;
Out.Read(Req);
}
0 - File is open,
1 - IMS hit
3 - Unrecoverable error
- 4 - Error with error content page */
+ 4 - Error with error content page
+ 5 - Unrecoverable non-server error (close the connection) */
int HttpMethod::DealWithHeaders(FetchResult &Res,ServerState *Srv)
{
// Not Modified
delete File;
File = new FileFd(Queue->DestFile,FileFd::WriteAny);
if (_error->PendingError() == true)
- return 3;
+ return 5;
FailFile = Queue->DestFile;
FailFd = File->Fd();
if (Srv->In.MD5->AddFD(File->Fd(),Srv->StartPos) == false)
{
_error->Errno("read","Problem hashing file");
- return 3;
+ return 5;
}
lseek(File->Fd(),0,SEEK_END);
}
exit(100);
}
/*}}}*/
+// HttpMethod::Fetch - Fetch an item /*{{{*/
+// ---------------------------------------------------------------------
+/* This adds an item to the pipeline. We keep the pipeline at a fixed
+ depth. */
+bool HttpMethod::Fetch(FetchItem *)
+{
+ if (Server == 0)
+ return true;
+
+ // Queue the requests
+ int Depth = -1;
+ bool Tail = false;
+ for (FetchItem *I = Queue; I != 0 && Depth < 5; I = I->Next, Depth++)
+ {
+ // Make sure we stick with the same server
+ if (Server->Comp(I->Uri) == false)
+ break;
+
+ if (QueueBack == I)
+ Tail = true;
+ if (Tail == true)
+ {
+ Depth++;
+ QueueBack = I->Next;
+ SendReq(I,Server->Out);
+ continue;
+ }
+ }
+
+ return true;
+};
+ /*}}}*/
// HttpMethod::Loop - Main loop /*{{{*/
// ---------------------------------------------------------------------
/* */
signal(SIGTERM,SigTerm);
signal(SIGINT,SigTerm);
- ServerState *Server = 0;
+ Server = 0;
int FailCounter = 0;
while (1)
Fail();
continue;
}
-
- // Queue the request
- SendReq(Queue,Server->Out);
+ // Fill the pipeline.
+ Fetch(0);
+
// Fetch the next URL header data from the server.
switch (Server->RunHeaders())
{
continue;
}
};
-
+
// Decide what to do.
FetchResult Res;
Res.Filename = Queue->DestFile;
Fail();
break;
}
+
+ // Hard internal error, kill the connection and fail
+ case 5:
+ {
+ Fail();
+ Server->Close();
+ break;
+ }
// We need to flush the data, the header is like a 404 w/ error text
case 4: