25
25
##################################################################### */
27
27
// Include Files /*{{{*/
28
#include <apt-pkg/contrib/fileutl.h>
28
#include <apt-pkg/fileutl.h>
29
29
#include <apt-pkg/acquire-method.h>
30
#include <apt-pkg/contrib/error.h>
31
#include <apt-pkg/contrib/hashes.h>
30
#include <apt-pkg/error.h>
31
#include <apt-pkg/hashes.h>
32
#include <apt-pkg/netrc.h>
33
34
#include <sys/stat.h>
34
35
#include <sys/time.h>
552
553
// Evil servers return no version
553
554
if (Line[4] == '/')
555
if (sscanf(Line.c_str(),"HTTP/%u.%u %u %[^\n]",&Major,&Minor,
556
if (sscanf(Line.c_str(),"HTTP/%u.%u %u%[^\n]",&Major,&Minor,
556
557
&Result,Code) != 4)
557
558
return _error->Error(_("The HTTP server sent an invalid reply header"));
563
if (sscanf(Line.c_str(),"HTTP %u %[^\n]",&Result,Code) != 2)
564
if (sscanf(Line.c_str(),"HTTP %u%[^\n]",&Result,Code) != 2)
564
565
return _error->Error(_("The HTTP server sent an invalid reply header"));
681
682
and a no-store directive for archives. */
682
683
sprintf(Buf,"GET %s HTTP/1.1\r\nHost: %s\r\n",
683
684
Itm->Uri.c_str(),ProperHost.c_str());
684
// only generate a cache control header if we actually want to
686
if (_config->FindB("Acquire::http::No-Cache",false) == false)
688
if (Itm->IndexFile == true)
689
sprintf(Buf+strlen(Buf),"Cache-Control: max-age=%u\r\n",
690
_config->FindI("Acquire::http::Max-Age",0));
693
if (_config->FindB("Acquire::http::No-Store",false) == true)
694
strcat(Buf,"Cache-Control: no-store\r\n");
698
// generate a no-cache header if needed
699
if (_config->FindB("Acquire::http::No-Cache",false) == true)
686
// generate a cache control header (if needed)
687
if (_config->FindB("Acquire::http::No-Cache",false) == true)
700
689
strcat(Buf,"Cache-Control: no-cache\r\nPragma: no-cache\r\n");
693
if (Itm->IndexFile == true)
695
sprintf(Buf+strlen(Buf),"Cache-Control: max-age=%u\r\n",
696
_config->FindI("Acquire::http::Max-Age",0));
700
if (_config->FindB("Acquire::http::No-Store",false) == true)
701
strcat(Buf,"Cache-Control: no-store\r\n");
703
706
string Req = Buf;
724
727
Req += string("Proxy-Authorization: Basic ") +
725
728
Base64Encode(Proxy.User + ":" + Proxy.Password) + "\r\n";
730
maybe_add_auth (Uri, _config->FindFile("Dir::Etc::netrc"));
727
731
if (Uri.User.empty() == false || Uri.Password.empty() == false)
728
733
Req += string("Authorization: Basic ") +
729
734
Base64Encode(Uri.User + ":" + Uri.Password) + "\r\n";
731
Req += "User-Agent: Debian APT-HTTP/1.3 ("VERSION")\r\n\r\n";
736
Req += "User-Agent: " + _config->Find("Acquire::http::User-Agent",
737
"Debian APT-HTTP/1.3 ("VERSION")") + "\r\n\r\n";
733
739
if (Debug == true)
734
740
cerr << Req << endl;
1330
// HttpMethod::AutoDetectProxy - auto detect proxy /*{{{*/
1331
// ---------------------------------------------------------------------
1333
bool HttpMethod::AutoDetectProxy()
1335
if (AutoDetectProxyCmd.empty())
1339
clog << "Using auto proxy detect command: " << AutoDetectProxyCmd << endl;
1341
int Pipes[2] = {-1,-1};
1342
if (pipe(Pipes) != 0)
1343
return _error->Errno("pipe", "Failed to create Pipe");
1345
pid_t Process = ExecFork();
1348
dup2(Pipes[1],STDOUT_FILENO);
1349
SetCloseExec(STDOUT_FILENO,false);
1351
const char *Args[2];
1352
Args[0] = AutoDetectProxyCmd.c_str();
1354
execv(Args[0],(char **)Args);
1355
cerr << "Failed to exec method " << Args[0] << endl;
1359
int InFd = Pipes[0];
1360
if (read(InFd, buf, sizeof(buf)) < 0)
1361
return _error->Errno("read", "Failed to read");
1362
ExecWait(Process, "ProxyAutoDetect");
1365
clog << "auto detect command returned: '" << buf << "'" << endl;
1367
if (strstr(buf, "http://") == buf)
1368
_config->Set("Acquire::http::proxy", _strstrip(buf));
1323
1376
setlocale(LC_ALL, "");
1377
// ignore SIGPIPE, this can happen on write() if the socket
1378
// closes the connection (this is dealt with via ServerDie())
1379
signal(SIGPIPE, SIG_IGN);
1325
1381
HttpMethod Mth;
1327
1382
return Mth.Loop();