http.cc 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: http.cc,v 1.59 2004/05/08 19:42:35 mdz Exp $
  4. /* ######################################################################
  5. HTTP Acquire Method - This is the HTTP aquire method for APT.
  6. It uses HTTP/1.1 and many of the fancy options there-in, such as
  7. pipelining, range, if-range and so on.
  8. It is based on a doubly buffered select loop. A groupe of requests are
  9. fed into a single output buffer that is constantly fed out the
  10. socket. This provides ideal pipelining as in many cases all of the
  11. requests will fit into a single packet. The input socket is buffered
  12. the same way and fed into the fd for the file (may be a pipe in future).
  13. This double buffering provides fairly substantial transfer rates,
  14. compared to wget the http method is about 4% faster. Most importantly,
  15. when HTTP is compared with FTP as a protocol the speed difference is
  16. huge. In tests over the internet from two sites to llug (via ATM) this
  17. program got 230k/s sustained http transfer rates. FTP on the other
  18. hand topped out at 170k/s. That combined with the time to setup the
  19. FTP connection makes HTTP a vastly superior protocol.
  20. ##################################################################### */
  21. /*}}}*/
  22. // Include Files /*{{{*/
  23. #include <config.h>
  24. #include <apt-pkg/fileutl.h>
  25. #include <apt-pkg/acquire-method.h>
  26. #include <apt-pkg/configuration.h>
  27. #include <apt-pkg/error.h>
  28. #include <apt-pkg/hashes.h>
  29. #include <apt-pkg/netrc.h>
  30. #include <sys/stat.h>
  31. #include <sys/time.h>
  32. #include <utime.h>
  33. #include <unistd.h>
  34. #include <signal.h>
  35. #include <stdio.h>
  36. #include <errno.h>
  37. #include <string.h>
  38. #include <iostream>
  39. #include <map>
  40. // Internet stuff
  41. #include <netdb.h>
  42. #include "config.h"
  43. #include "connect.h"
  44. #include "rfc2553emu.h"
  45. #include "http.h"
  46. #include <apti18n.h>
  47. /*}}}*/
  48. using namespace std;
  49. string HttpMethod::FailFile;
  50. int HttpMethod::FailFd = -1;
  51. time_t HttpMethod::FailTime = 0;
  52. unsigned long PipelineDepth = 10;
  53. unsigned long TimeOut = 120;
  54. bool AllowRedirect = false;
  55. bool Debug = false;
  56. URI Proxy;
  57. unsigned long long CircleBuf::BwReadLimit=0;
  58. unsigned long long CircleBuf::BwTickReadData=0;
  59. struct timeval CircleBuf::BwReadTick={0,0};
  60. const unsigned int CircleBuf::BW_HZ=10;
  61. // CircleBuf::CircleBuf - Circular input buffer /*{{{*/
  62. // ---------------------------------------------------------------------
  63. /* */
  64. CircleBuf::CircleBuf(unsigned long long Size) : Size(Size), Hash(0)
  65. {
  66. Buf = new unsigned char[Size];
  67. Reset();
  68. CircleBuf::BwReadLimit = _config->FindI("Acquire::http::Dl-Limit",0)*1024;
  69. }
  70. /*}}}*/
  71. // CircleBuf::Reset - Reset to the default state /*{{{*/
  72. // ---------------------------------------------------------------------
  73. /* */
  74. void CircleBuf::Reset()
  75. {
  76. InP = 0;
  77. OutP = 0;
  78. StrPos = 0;
  79. MaxGet = (unsigned long long)-1;
  80. OutQueue = string();
  81. if (Hash != 0)
  82. {
  83. delete Hash;
  84. Hash = new Hashes;
  85. }
  86. };
  87. /*}}}*/
  88. // CircleBuf::Read - Read from a FD into the circular buffer /*{{{*/
  89. // ---------------------------------------------------------------------
  90. /* This fills up the buffer with as much data as is in the FD, assuming it
  91. is non-blocking.. */
  92. bool CircleBuf::Read(int Fd)
  93. {
  94. unsigned long long BwReadMax;
  95. while (1)
  96. {
  97. // Woops, buffer is full
  98. if (InP - OutP == Size)
  99. return true;
  100. // what's left to read in this tick
  101. BwReadMax = CircleBuf::BwReadLimit/BW_HZ;
  102. if(CircleBuf::BwReadLimit) {
  103. struct timeval now;
  104. gettimeofday(&now,0);
  105. unsigned long long d = (now.tv_sec-CircleBuf::BwReadTick.tv_sec)*1000000 +
  106. now.tv_usec-CircleBuf::BwReadTick.tv_usec;
  107. if(d > 1000000/BW_HZ) {
  108. CircleBuf::BwReadTick = now;
  109. CircleBuf::BwTickReadData = 0;
  110. }
  111. if(CircleBuf::BwTickReadData >= BwReadMax) {
  112. usleep(1000000/BW_HZ);
  113. return true;
  114. }
  115. }
  116. // Write the buffer segment
  117. ssize_t Res;
  118. if(CircleBuf::BwReadLimit) {
  119. Res = read(Fd,Buf + (InP%Size),
  120. BwReadMax > LeftRead() ? LeftRead() : BwReadMax);
  121. } else
  122. Res = read(Fd,Buf + (InP%Size),LeftRead());
  123. if(Res > 0 && BwReadLimit > 0)
  124. CircleBuf::BwTickReadData += Res;
  125. if (Res == 0)
  126. return false;
  127. if (Res < 0)
  128. {
  129. if (errno == EAGAIN)
  130. return true;
  131. return false;
  132. }
  133. if (InP == 0)
  134. gettimeofday(&Start,0);
  135. InP += Res;
  136. }
  137. }
  138. /*}}}*/
  139. // CircleBuf::Read - Put the string into the buffer /*{{{*/
  140. // ---------------------------------------------------------------------
  141. /* This will hold the string in and fill the buffer with it as it empties */
  142. bool CircleBuf::Read(string Data)
  143. {
  144. OutQueue += Data;
  145. FillOut();
  146. return true;
  147. }
  148. /*}}}*/
  149. // CircleBuf::FillOut - Fill the buffer from the output queue /*{{{*/
  150. // ---------------------------------------------------------------------
  151. /* */
  152. void CircleBuf::FillOut()
  153. {
  154. if (OutQueue.empty() == true)
  155. return;
  156. while (1)
  157. {
  158. // Woops, buffer is full
  159. if (InP - OutP == Size)
  160. return;
  161. // Write the buffer segment
  162. unsigned long long Sz = LeftRead();
  163. if (OutQueue.length() - StrPos < Sz)
  164. Sz = OutQueue.length() - StrPos;
  165. memcpy(Buf + (InP%Size),OutQueue.c_str() + StrPos,Sz);
  166. // Advance
  167. StrPos += Sz;
  168. InP += Sz;
  169. if (OutQueue.length() == StrPos)
  170. {
  171. StrPos = 0;
  172. OutQueue = "";
  173. return;
  174. }
  175. }
  176. }
  177. /*}}}*/
  178. // CircleBuf::Write - Write from the buffer into a FD /*{{{*/
  179. // ---------------------------------------------------------------------
  180. /* This empties the buffer into the FD. */
  181. bool CircleBuf::Write(int Fd)
  182. {
  183. while (1)
  184. {
  185. FillOut();
  186. // Woops, buffer is empty
  187. if (OutP == InP)
  188. return true;
  189. if (OutP == MaxGet)
  190. return true;
  191. // Write the buffer segment
  192. ssize_t Res;
  193. Res = write(Fd,Buf + (OutP%Size),LeftWrite());
  194. if (Res == 0)
  195. return false;
  196. if (Res < 0)
  197. {
  198. if (errno == EAGAIN)
  199. return true;
  200. return false;
  201. }
  202. if (Hash != 0)
  203. Hash->Add(Buf + (OutP%Size),Res);
  204. OutP += Res;
  205. }
  206. }
  207. /*}}}*/
  208. // CircleBuf::WriteTillEl - Write from the buffer to a string /*{{{*/
  209. // ---------------------------------------------------------------------
  210. /* This copies till the first empty line */
  211. bool CircleBuf::WriteTillEl(string &Data,bool Single)
  212. {
  213. // We cheat and assume it is unneeded to have more than one buffer load
  214. for (unsigned long long I = OutP; I < InP; I++)
  215. {
  216. if (Buf[I%Size] != '\n')
  217. continue;
  218. ++I;
  219. if (Single == false)
  220. {
  221. if (I < InP && Buf[I%Size] == '\r')
  222. ++I;
  223. if (I >= InP || Buf[I%Size] != '\n')
  224. continue;
  225. ++I;
  226. }
  227. Data = "";
  228. while (OutP < I)
  229. {
  230. unsigned long long Sz = LeftWrite();
  231. if (Sz == 0)
  232. return false;
  233. if (I - OutP < Sz)
  234. Sz = I - OutP;
  235. Data += string((char *)(Buf + (OutP%Size)),Sz);
  236. OutP += Sz;
  237. }
  238. return true;
  239. }
  240. return false;
  241. }
  242. /*}}}*/
  243. // CircleBuf::Stats - Print out stats information /*{{{*/
  244. // ---------------------------------------------------------------------
  245. /* */
  246. void CircleBuf::Stats()
  247. {
  248. if (InP == 0)
  249. return;
  250. struct timeval Stop;
  251. gettimeofday(&Stop,0);
  252. /* float Diff = Stop.tv_sec - Start.tv_sec +
  253. (float)(Stop.tv_usec - Start.tv_usec)/1000000;
  254. clog << "Got " << InP << " in " << Diff << " at " << InP/Diff << endl;*/
  255. }
  256. /*}}}*/
  257. CircleBuf::~CircleBuf()
  258. {
  259. delete [] Buf;
  260. delete Hash;
  261. }
  262. // ServerState::ServerState - Constructor /*{{{*/
  263. // ---------------------------------------------------------------------
  264. /* */
  265. ServerState::ServerState(URI Srv,HttpMethod *Owner) : Owner(Owner),
  266. In(64*1024), Out(4*1024),
  267. ServerName(Srv)
  268. {
  269. Reset();
  270. }
  271. /*}}}*/
  272. // ServerState::Open - Open a connection to the server /*{{{*/
  273. // ---------------------------------------------------------------------
  274. /* This opens a connection to the server. */
  275. bool ServerState::Open()
  276. {
  277. // Use the already open connection if possible.
  278. if (ServerFd != -1)
  279. return true;
  280. Close();
  281. In.Reset();
  282. Out.Reset();
  283. Persistent = true;
  284. // Determine the proxy setting
  285. string SpecificProxy = _config->Find("Acquire::http::Proxy::" + ServerName.Host);
  286. if (!SpecificProxy.empty())
  287. {
  288. if (SpecificProxy == "DIRECT")
  289. Proxy = "";
  290. else
  291. Proxy = SpecificProxy;
  292. }
  293. else
  294. {
  295. string DefProxy = _config->Find("Acquire::http::Proxy");
  296. if (!DefProxy.empty())
  297. {
  298. Proxy = DefProxy;
  299. }
  300. else
  301. {
  302. char* result = getenv("http_proxy");
  303. Proxy = result ? result : "";
  304. }
  305. }
  306. // Parse no_proxy, a , separated list of domains
  307. if (getenv("no_proxy") != 0)
  308. {
  309. if (CheckDomainList(ServerName.Host,getenv("no_proxy")) == true)
  310. Proxy = "";
  311. }
  312. // Determine what host and port to use based on the proxy settings
  313. int Port = 0;
  314. string Host;
  315. if (Proxy.empty() == true || Proxy.Host.empty() == true)
  316. {
  317. if (ServerName.Port != 0)
  318. Port = ServerName.Port;
  319. Host = ServerName.Host;
  320. }
  321. else
  322. {
  323. if (Proxy.Port != 0)
  324. Port = Proxy.Port;
  325. Host = Proxy.Host;
  326. }
  327. // Connect to the remote server
  328. if (Connect(Host,Port,"http",80,ServerFd,TimeOut,Owner) == false)
  329. return false;
  330. return true;
  331. }
  332. /*}}}*/
  333. // ServerState::Close - Close a connection to the server /*{{{*/
  334. // ---------------------------------------------------------------------
  335. /* */
  336. bool ServerState::Close()
  337. {
  338. close(ServerFd);
  339. ServerFd = -1;
  340. return true;
  341. }
  342. /*}}}*/
  343. // ServerState::RunHeaders - Get the headers before the data /*{{{*/
  344. // ---------------------------------------------------------------------
  345. /* Returns 0 if things are OK, 1 if an IO error occurred and 2 if a header
  346. parse error occurred */
  347. ServerState::RunHeadersResult ServerState::RunHeaders()
  348. {
  349. State = Header;
  350. Owner->Status(_("Waiting for headers"));
  351. Major = 0;
  352. Minor = 0;
  353. Result = 0;
  354. Size = 0;
  355. StartPos = 0;
  356. Encoding = Closes;
  357. HaveContent = false;
  358. time(&Date);
  359. do
  360. {
  361. string Data;
  362. if (In.WriteTillEl(Data) == false)
  363. continue;
  364. if (Debug == true)
  365. clog << Data;
  366. for (string::const_iterator I = Data.begin(); I < Data.end(); ++I)
  367. {
  368. string::const_iterator J = I;
  369. for (; J != Data.end() && *J != '\n' && *J != '\r'; ++J);
  370. if (HeaderLine(string(I,J)) == false)
  371. return RUN_HEADERS_PARSE_ERROR;
  372. I = J;
  373. }
  374. // 100 Continue is a Nop...
  375. if (Result == 100)
  376. continue;
  377. // Tidy up the connection persistance state.
  378. if (Encoding == Closes && HaveContent == true)
  379. Persistent = false;
  380. return RUN_HEADERS_OK;
  381. }
  382. while (Owner->Go(false,this) == true);
  383. return RUN_HEADERS_IO_ERROR;
  384. }
  385. /*}}}*/
  386. // ServerState::RunData - Transfer the data from the socket /*{{{*/
  387. // ---------------------------------------------------------------------
  388. /* */
  389. bool ServerState::RunData()
  390. {
  391. State = Data;
  392. // Chunked transfer encoding is fun..
  393. if (Encoding == Chunked)
  394. {
  395. while (1)
  396. {
  397. // Grab the block size
  398. bool Last = true;
  399. string Data;
  400. In.Limit(-1);
  401. do
  402. {
  403. if (In.WriteTillEl(Data,true) == true)
  404. break;
  405. }
  406. while ((Last = Owner->Go(false,this)) == true);
  407. if (Last == false)
  408. return false;
  409. // See if we are done
  410. unsigned long long Len = strtoull(Data.c_str(),0,16);
  411. if (Len == 0)
  412. {
  413. In.Limit(-1);
  414. // We have to remove the entity trailer
  415. Last = true;
  416. do
  417. {
  418. if (In.WriteTillEl(Data,true) == true && Data.length() <= 2)
  419. break;
  420. }
  421. while ((Last = Owner->Go(false,this)) == true);
  422. if (Last == false)
  423. return false;
  424. return !_error->PendingError();
  425. }
  426. // Transfer the block
  427. In.Limit(Len);
  428. while (Owner->Go(true,this) == true)
  429. if (In.IsLimit() == true)
  430. break;
  431. // Error
  432. if (In.IsLimit() == false)
  433. return false;
  434. // The server sends an extra new line before the next block specifier..
  435. In.Limit(-1);
  436. Last = true;
  437. do
  438. {
  439. if (In.WriteTillEl(Data,true) == true)
  440. break;
  441. }
  442. while ((Last = Owner->Go(false,this)) == true);
  443. if (Last == false)
  444. return false;
  445. }
  446. }
  447. else
  448. {
  449. /* Closes encoding is used when the server did not specify a size, the
  450. loss of the connection means we are done */
  451. if (Encoding == Closes)
  452. In.Limit(-1);
  453. else
  454. In.Limit(Size - StartPos);
  455. // Just transfer the whole block.
  456. do
  457. {
  458. if (In.IsLimit() == false)
  459. continue;
  460. In.Limit(-1);
  461. return !_error->PendingError();
  462. }
  463. while (Owner->Go(true,this) == true);
  464. }
  465. return Owner->Flush(this) && !_error->PendingError();
  466. }
  467. /*}}}*/
  468. // ServerState::HeaderLine - Process a header line /*{{{*/
  469. // ---------------------------------------------------------------------
  470. /* */
  471. bool ServerState::HeaderLine(string Line)
  472. {
  473. if (Line.empty() == true)
  474. return true;
  475. string::size_type Pos = Line.find(' ');
  476. if (Pos == string::npos || Pos+1 > Line.length())
  477. {
  478. // Blah, some servers use "connection:closes", evil.
  479. Pos = Line.find(':');
  480. if (Pos == string::npos || Pos + 2 > Line.length())
  481. return _error->Error(_("Bad header line"));
  482. Pos++;
  483. }
  484. // Parse off any trailing spaces between the : and the next word.
  485. string::size_type Pos2 = Pos;
  486. while (Pos2 < Line.length() && isspace(Line[Pos2]) != 0)
  487. Pos2++;
  488. string Tag = string(Line,0,Pos);
  489. string Val = string(Line,Pos2);
  490. if (stringcasecmp(Tag.c_str(),Tag.c_str()+4,"HTTP") == 0)
  491. {
  492. // Evil servers return no version
  493. if (Line[4] == '/')
  494. {
  495. int const elements = sscanf(Line.c_str(),"HTTP/%u.%u %u%[^\n]",&Major,&Minor,&Result,Code);
  496. if (elements == 3)
  497. {
  498. Code[0] = '\0';
  499. if (Debug == true)
  500. clog << "HTTP server doesn't give Reason-Phrase for " << Result << std::endl;
  501. }
  502. else if (elements != 4)
  503. return _error->Error(_("The HTTP server sent an invalid reply header"));
  504. }
  505. else
  506. {
  507. Major = 0;
  508. Minor = 9;
  509. if (sscanf(Line.c_str(),"HTTP %u%[^\n]",&Result,Code) != 2)
  510. return _error->Error(_("The HTTP server sent an invalid reply header"));
  511. }
  512. /* Check the HTTP response header to get the default persistance
  513. state. */
  514. if (Major < 1)
  515. Persistent = false;
  516. else
  517. {
  518. if (Major == 1 && Minor <= 0)
  519. Persistent = false;
  520. else
  521. Persistent = true;
  522. }
  523. return true;
  524. }
  525. if (stringcasecmp(Tag,"Content-Length:") == 0)
  526. {
  527. if (Encoding == Closes)
  528. Encoding = Stream;
  529. HaveContent = true;
  530. // The length is already set from the Content-Range header
  531. if (StartPos != 0)
  532. return true;
  533. if (sscanf(Val.c_str(),"%llu",&Size) != 1)
  534. return _error->Error(_("The HTTP server sent an invalid Content-Length header"));
  535. return true;
  536. }
  537. if (stringcasecmp(Tag,"Content-Type:") == 0)
  538. {
  539. HaveContent = true;
  540. return true;
  541. }
  542. if (stringcasecmp(Tag,"Content-Range:") == 0)
  543. {
  544. HaveContent = true;
  545. if (sscanf(Val.c_str(),"bytes %llu-%*u/%llu",&StartPos,&Size) != 2)
  546. return _error->Error(_("The HTTP server sent an invalid Content-Range header"));
  547. if ((unsigned long long)StartPos > Size)
  548. return _error->Error(_("This HTTP server has broken range support"));
  549. return true;
  550. }
  551. if (stringcasecmp(Tag,"Transfer-Encoding:") == 0)
  552. {
  553. HaveContent = true;
  554. if (stringcasecmp(Val,"chunked") == 0)
  555. Encoding = Chunked;
  556. return true;
  557. }
  558. if (stringcasecmp(Tag,"Connection:") == 0)
  559. {
  560. if (stringcasecmp(Val,"close") == 0)
  561. Persistent = false;
  562. if (stringcasecmp(Val,"keep-alive") == 0)
  563. Persistent = true;
  564. return true;
  565. }
  566. if (stringcasecmp(Tag,"Last-Modified:") == 0)
  567. {
  568. if (RFC1123StrToTime(Val.c_str(), Date) == false)
  569. return _error->Error(_("Unknown date format"));
  570. return true;
  571. }
  572. if (stringcasecmp(Tag,"Location:") == 0)
  573. {
  574. Location = Val;
  575. return true;
  576. }
  577. return true;
  578. }
  579. /*}}}*/
  580. // HttpMethod::SendReq - Send the HTTP request /*{{{*/
  581. // ---------------------------------------------------------------------
  582. /* This places the http request in the outbound buffer */
  583. void HttpMethod::SendReq(FetchItem *Itm,CircleBuf &Out)
  584. {
  585. URI Uri = Itm->Uri;
  586. // The HTTP server expects a hostname with a trailing :port
  587. char Buf[1000];
  588. string ProperHost = Uri.Host;
  589. if (Uri.Port != 0)
  590. {
  591. sprintf(Buf,":%u",Uri.Port);
  592. ProperHost += Buf;
  593. }
  594. // Just in case.
  595. if (Itm->Uri.length() >= sizeof(Buf))
  596. abort();
  597. /* Build the request. We include a keep-alive header only for non-proxy
  598. requests. This is to tweak old http/1.0 servers that do support keep-alive
  599. but not HTTP/1.1 automatic keep-alive. Doing this with a proxy server
  600. will glitch HTTP/1.0 proxies because they do not filter it out and
  601. pass it on, HTTP/1.1 says the connection should default to keep alive
  602. and we expect the proxy to do this */
  603. if (Proxy.empty() == true || Proxy.Host.empty())
  604. sprintf(Buf,"GET %s HTTP/1.1\r\nHost: %s\r\nConnection: keep-alive\r\n",
  605. QuoteString(Uri.Path,"~").c_str(),ProperHost.c_str());
  606. else
  607. {
  608. /* Generate a cache control header if necessary. We place a max
  609. cache age on index files, optionally set a no-cache directive
  610. and a no-store directive for archives. */
  611. sprintf(Buf,"GET %s HTTP/1.1\r\nHost: %s\r\n",
  612. Itm->Uri.c_str(),ProperHost.c_str());
  613. }
  614. // generate a cache control header (if needed)
  615. if (_config->FindB("Acquire::http::No-Cache",false) == true)
  616. {
  617. strcat(Buf,"Cache-Control: no-cache\r\nPragma: no-cache\r\n");
  618. }
  619. else
  620. {
  621. if (Itm->IndexFile == true)
  622. {
  623. sprintf(Buf+strlen(Buf),"Cache-Control: max-age=%u\r\n",
  624. _config->FindI("Acquire::http::Max-Age",0));
  625. }
  626. else
  627. {
  628. if (_config->FindB("Acquire::http::No-Store",false) == true)
  629. strcat(Buf,"Cache-Control: no-store\r\n");
  630. }
  631. }
  632. // If we ask for uncompressed files servers might respond with content-
  633. // negotation which lets us end up with compressed files we do not support,
  634. // see 657029, 657560 and co, so if we have no extension on the request
  635. // ask for text only. As a sidenote: If there is nothing to negotate servers
  636. // seem to be nice and ignore it.
  637. if (_config->FindB("Acquire::http::SendAccept", true) == true)
  638. {
  639. size_t const filepos = Itm->Uri.find_last_of('/');
  640. string const file = Itm->Uri.substr(filepos + 1);
  641. if (flExtension(file) == file)
  642. strcat(Buf,"Accept: text/*\r\n");
  643. }
  644. string Req = Buf;
  645. // Check for a partial file
  646. struct stat SBuf;
  647. if (stat(Itm->DestFile.c_str(),&SBuf) >= 0 && SBuf.st_size > 0)
  648. {
  649. // In this case we send an if-range query with a range header
  650. sprintf(Buf,"Range: bytes=%lli-\r\nIf-Range: %s\r\n",(long long)SBuf.st_size - 1,
  651. TimeRFC1123(SBuf.st_mtime).c_str());
  652. Req += Buf;
  653. }
  654. else
  655. {
  656. if (Itm->LastModified != 0)
  657. {
  658. sprintf(Buf,"If-Modified-Since: %s\r\n",TimeRFC1123(Itm->LastModified).c_str());
  659. Req += Buf;
  660. }
  661. }
  662. if (Proxy.User.empty() == false || Proxy.Password.empty() == false)
  663. Req += string("Proxy-Authorization: Basic ") +
  664. Base64Encode(Proxy.User + ":" + Proxy.Password) + "\r\n";
  665. maybe_add_auth (Uri, _config->FindFile("Dir::Etc::netrc"));
  666. if (Uri.User.empty() == false || Uri.Password.empty() == false)
  667. {
  668. Req += string("Authorization: Basic ") +
  669. Base64Encode(Uri.User + ":" + Uri.Password) + "\r\n";
  670. }
  671. Req += "User-Agent: " + _config->Find("Acquire::http::User-Agent",
  672. "Debian APT-HTTP/1.3 ("VERSION")") + "\r\n\r\n";
  673. if (Debug == true)
  674. cerr << Req << endl;
  675. Out.Read(Req);
  676. }
  677. /*}}}*/
  678. // HttpMethod::Go - Run a single loop /*{{{*/
  679. // ---------------------------------------------------------------------
  680. /* This runs the select loop over the server FDs, Output file FDs and
  681. stdin. */
  682. bool HttpMethod::Go(bool ToFile,ServerState *Srv)
  683. {
  684. // Server has closed the connection
  685. if (Srv->ServerFd == -1 && (Srv->In.WriteSpace() == false ||
  686. ToFile == false))
  687. return false;
  688. fd_set rfds,wfds;
  689. FD_ZERO(&rfds);
  690. FD_ZERO(&wfds);
  691. /* Add the server. We only send more requests if the connection will
  692. be persisting */
  693. if (Srv->Out.WriteSpace() == true && Srv->ServerFd != -1
  694. && Srv->Persistent == true)
  695. FD_SET(Srv->ServerFd,&wfds);
  696. if (Srv->In.ReadSpace() == true && Srv->ServerFd != -1)
  697. FD_SET(Srv->ServerFd,&rfds);
  698. // Add the file
  699. int FileFD = -1;
  700. if (File != 0)
  701. FileFD = File->Fd();
  702. if (Srv->In.WriteSpace() == true && ToFile == true && FileFD != -1)
  703. FD_SET(FileFD,&wfds);
  704. // Add stdin
  705. if (_config->FindB("Acquire::http::DependOnSTDIN", true) == true)
  706. FD_SET(STDIN_FILENO,&rfds);
  707. // Figure out the max fd
  708. int MaxFd = FileFD;
  709. if (MaxFd < Srv->ServerFd)
  710. MaxFd = Srv->ServerFd;
  711. // Select
  712. struct timeval tv;
  713. tv.tv_sec = TimeOut;
  714. tv.tv_usec = 0;
  715. int Res = 0;
  716. if ((Res = select(MaxFd+1,&rfds,&wfds,0,&tv)) < 0)
  717. {
  718. if (errno == EINTR)
  719. return true;
  720. return _error->Errno("select",_("Select failed"));
  721. }
  722. if (Res == 0)
  723. {
  724. _error->Error(_("Connection timed out"));
  725. return ServerDie(Srv);
  726. }
  727. // Handle server IO
  728. if (Srv->ServerFd != -1 && FD_ISSET(Srv->ServerFd,&rfds))
  729. {
  730. errno = 0;
  731. if (Srv->In.Read(Srv->ServerFd) == false)
  732. return ServerDie(Srv);
  733. }
  734. if (Srv->ServerFd != -1 && FD_ISSET(Srv->ServerFd,&wfds))
  735. {
  736. errno = 0;
  737. if (Srv->Out.Write(Srv->ServerFd) == false)
  738. return ServerDie(Srv);
  739. }
  740. // Send data to the file
  741. if (FileFD != -1 && FD_ISSET(FileFD,&wfds))
  742. {
  743. if (Srv->In.Write(FileFD) == false)
  744. return _error->Errno("write",_("Error writing to output file"));
  745. }
  746. // Handle commands from APT
  747. if (FD_ISSET(STDIN_FILENO,&rfds))
  748. {
  749. if (Run(true) != -1)
  750. exit(100);
  751. }
  752. return true;
  753. }
  754. /*}}}*/
  755. // HttpMethod::Flush - Dump the buffer into the file /*{{{*/
  756. // ---------------------------------------------------------------------
  757. /* This takes the current input buffer from the Server FD and writes it
  758. into the file */
  759. bool HttpMethod::Flush(ServerState *Srv)
  760. {
  761. if (File != 0)
  762. {
  763. // on GNU/kFreeBSD, apt dies on /dev/null because non-blocking
  764. // can't be set
  765. if (File->Name() != "/dev/null")
  766. SetNonBlock(File->Fd(),false);
  767. if (Srv->In.WriteSpace() == false)
  768. return true;
  769. while (Srv->In.WriteSpace() == true)
  770. {
  771. if (Srv->In.Write(File->Fd()) == false)
  772. return _error->Errno("write",_("Error writing to file"));
  773. if (Srv->In.IsLimit() == true)
  774. return true;
  775. }
  776. if (Srv->In.IsLimit() == true || Srv->Encoding == ServerState::Closes)
  777. return true;
  778. }
  779. return false;
  780. }
  781. /*}}}*/
  782. // HttpMethod::ServerDie - The server has closed the connection. /*{{{*/
  783. // ---------------------------------------------------------------------
  784. /* */
  785. bool HttpMethod::ServerDie(ServerState *Srv)
  786. {
  787. unsigned int LErrno = errno;
  788. // Dump the buffer to the file
  789. if (Srv->State == ServerState::Data)
  790. {
  791. // on GNU/kFreeBSD, apt dies on /dev/null because non-blocking
  792. // can't be set
  793. if (File->Name() != "/dev/null")
  794. SetNonBlock(File->Fd(),false);
  795. while (Srv->In.WriteSpace() == true)
  796. {
  797. if (Srv->In.Write(File->Fd()) == false)
  798. return _error->Errno("write",_("Error writing to the file"));
  799. // Done
  800. if (Srv->In.IsLimit() == true)
  801. return true;
  802. }
  803. }
  804. // See if this is because the server finished the data stream
  805. if (Srv->In.IsLimit() == false && Srv->State != ServerState::Header &&
  806. Srv->Encoding != ServerState::Closes)
  807. {
  808. Srv->Close();
  809. if (LErrno == 0)
  810. return _error->Error(_("Error reading from server. Remote end closed connection"));
  811. errno = LErrno;
  812. return _error->Errno("read",_("Error reading from server"));
  813. }
  814. else
  815. {
  816. Srv->In.Limit(-1);
  817. // Nothing left in the buffer
  818. if (Srv->In.WriteSpace() == false)
  819. return false;
  820. // We may have got multiple responses back in one packet..
  821. Srv->Close();
  822. return true;
  823. }
  824. return false;
  825. }
  826. /*}}}*/
  827. // HttpMethod::DealWithHeaders - Handle the retrieved header data /*{{{*/
  828. // ---------------------------------------------------------------------
  829. /* We look at the header data we got back from the server and decide what
  830. to do. Returns DealWithHeadersResult (see http.h for details).
  831. */
  832. HttpMethod::DealWithHeadersResult
  833. HttpMethod::DealWithHeaders(FetchResult &Res,ServerState *Srv)
  834. {
  835. // Not Modified
  836. if (Srv->Result == 304)
  837. {
  838. unlink(Queue->DestFile.c_str());
  839. Res.IMSHit = true;
  840. Res.LastModified = Queue->LastModified;
  841. return IMS_HIT;
  842. }
  843. /* Redirect
  844. *
  845. * Note that it is only OK for us to treat all redirection the same
  846. * because we *always* use GET, not other HTTP methods. There are
  847. * three redirection codes for which it is not appropriate that we
  848. * redirect. Pass on those codes so the error handling kicks in.
  849. */
  850. if (AllowRedirect
  851. && (Srv->Result > 300 && Srv->Result < 400)
  852. && (Srv->Result != 300 // Multiple Choices
  853. && Srv->Result != 304 // Not Modified
  854. && Srv->Result != 306)) // (Not part of HTTP/1.1, reserved)
  855. {
  856. if (Srv->Location.empty() == true);
  857. else if (Srv->Location[0] == '/' && Queue->Uri.empty() == false)
  858. {
  859. URI Uri = Queue->Uri;
  860. if (Uri.Host.empty() == false)
  861. {
  862. if (Uri.Port != 0)
  863. strprintf(NextURI, "http://%s:%u", Uri.Host.c_str(), Uri.Port);
  864. else
  865. NextURI = "http://" + Uri.Host;
  866. }
  867. else
  868. NextURI.clear();
  869. NextURI.append(DeQuoteString(Srv->Location));
  870. return TRY_AGAIN_OR_REDIRECT;
  871. }
  872. else
  873. {
  874. NextURI = DeQuoteString(Srv->Location);
  875. return TRY_AGAIN_OR_REDIRECT;
  876. }
  877. /* else pass through for error message */
  878. }
  879. /* We have a reply we dont handle. This should indicate a perm server
  880. failure */
  881. if (Srv->Result < 200 || Srv->Result >= 300)
  882. {
  883. char err[255];
  884. snprintf(err,sizeof(err)-1,"HttpError%i",Srv->Result);
  885. SetFailReason(err);
  886. _error->Error("%u %s",Srv->Result,Srv->Code);
  887. if (Srv->HaveContent == true)
  888. return ERROR_WITH_CONTENT_PAGE;
  889. return ERROR_UNRECOVERABLE;
  890. }
  891. // This is some sort of 2xx 'data follows' reply
  892. Res.LastModified = Srv->Date;
  893. Res.Size = Srv->Size;
  894. // Open the file
  895. delete File;
  896. File = new FileFd(Queue->DestFile,FileFd::WriteAny);
  897. if (_error->PendingError() == true)
  898. return ERROR_NOT_FROM_SERVER;
  899. FailFile = Queue->DestFile;
  900. FailFile.c_str(); // Make sure we dont do a malloc in the signal handler
  901. FailFd = File->Fd();
  902. FailTime = Srv->Date;
  903. delete Srv->In.Hash;
  904. Srv->In.Hash = new Hashes;
  905. // Set the expected size and read file for the hashes
  906. if (Srv->StartPos >= 0)
  907. {
  908. Res.ResumePoint = Srv->StartPos;
  909. File->Truncate(Srv->StartPos);
  910. if (Srv->In.Hash->AddFD(*File,Srv->StartPos) == false)
  911. {
  912. _error->Errno("read",_("Problem hashing file"));
  913. return ERROR_NOT_FROM_SERVER;
  914. }
  915. }
  916. SetNonBlock(File->Fd(),true);
  917. return FILE_IS_OPEN;
  918. }
  919. /*}}}*/
  920. // HttpMethod::SigTerm - Handle a fatal signal /*{{{*/
  921. // ---------------------------------------------------------------------
  922. /* This closes and timestamps the open file. This is neccessary to get
  923. resume behavoir on user abort */
  924. void HttpMethod::SigTerm(int)
  925. {
  926. if (FailFd == -1)
  927. _exit(100);
  928. close(FailFd);
  929. // Timestamp
  930. struct utimbuf UBuf;
  931. UBuf.actime = FailTime;
  932. UBuf.modtime = FailTime;
  933. utime(FailFile.c_str(),&UBuf);
  934. _exit(100);
  935. }
  936. /*}}}*/
  937. // HttpMethod::Fetch - Fetch an item /*{{{*/
  938. // ---------------------------------------------------------------------
  939. /* This adds an item to the pipeline. We keep the pipeline at a fixed
  940. depth. */
  941. bool HttpMethod::Fetch(FetchItem *)
  942. {
  943. if (Server == 0)
  944. return true;
  945. // Queue the requests
  946. int Depth = -1;
  947. for (FetchItem *I = Queue; I != 0 && Depth < (signed)PipelineDepth;
  948. I = I->Next, Depth++)
  949. {
  950. // If pipelining is disabled, we only queue 1 request
  951. if (Server->Pipeline == false && Depth >= 0)
  952. break;
  953. // Make sure we stick with the same server
  954. if (Server->Comp(I->Uri) == false)
  955. break;
  956. if (QueueBack == I)
  957. {
  958. QueueBack = I->Next;
  959. SendReq(I,Server->Out);
  960. continue;
  961. }
  962. }
  963. return true;
  964. };
  965. /*}}}*/
  966. // HttpMethod::Configuration - Handle a configuration message /*{{{*/
  967. // ---------------------------------------------------------------------
  968. /* We stash the desired pipeline depth */
  969. bool HttpMethod::Configuration(string Message)
  970. {
  971. if (pkgAcqMethod::Configuration(Message) == false)
  972. return false;
  973. AllowRedirect = _config->FindB("Acquire::http::AllowRedirect",true);
  974. TimeOut = _config->FindI("Acquire::http::Timeout",TimeOut);
  975. PipelineDepth = _config->FindI("Acquire::http::Pipeline-Depth",
  976. PipelineDepth);
  977. Debug = _config->FindB("Debug::Acquire::http",false);
  978. AutoDetectProxyCmd = _config->Find("Acquire::http::ProxyAutoDetect");
  979. // Get the proxy to use
  980. AutoDetectProxy();
  981. return true;
  982. }
  983. /*}}}*/
  984. // HttpMethod::Loop - Main loop /*{{{*/
  985. // ---------------------------------------------------------------------
  986. /* */
  987. int HttpMethod::Loop()
  988. {
  989. typedef vector<string> StringVector;
  990. typedef vector<string>::iterator StringVectorIterator;
  991. map<string, StringVector> Redirected;
  992. signal(SIGTERM,SigTerm);
  993. signal(SIGINT,SigTerm);
  994. Server = 0;
  995. int FailCounter = 0;
  996. while (1)
  997. {
  998. // We have no commands, wait for some to arrive
  999. if (Queue == 0)
  1000. {
  1001. if (WaitFd(STDIN_FILENO) == false)
  1002. return 0;
  1003. }
  1004. /* Run messages, we can accept 0 (no message) if we didn't
  1005. do a WaitFd above.. Otherwise the FD is closed. */
  1006. int Result = Run(true);
  1007. if (Result != -1 && (Result != 0 || Queue == 0))
  1008. {
  1009. if(FailReason.empty() == false ||
  1010. _config->FindB("Acquire::http::DependOnSTDIN", true) == true)
  1011. return 100;
  1012. else
  1013. return 0;
  1014. }
  1015. if (Queue == 0)
  1016. continue;
  1017. // Connect to the server
  1018. if (Server == 0 || Server->Comp(Queue->Uri) == false)
  1019. {
  1020. delete Server;
  1021. Server = new ServerState(Queue->Uri,this);
  1022. }
  1023. /* If the server has explicitly said this is the last connection
  1024. then we pre-emptively shut down the pipeline and tear down
  1025. the connection. This will speed up HTTP/1.0 servers a tad
  1026. since we don't have to wait for the close sequence to
  1027. complete */
  1028. if (Server->Persistent == false)
  1029. Server->Close();
  1030. // Reset the pipeline
  1031. if (Server->ServerFd == -1)
  1032. QueueBack = Queue;
  1033. // Connnect to the host
  1034. if (Server->Open() == false)
  1035. {
  1036. Fail(true);
  1037. delete Server;
  1038. Server = 0;
  1039. continue;
  1040. }
  1041. // Fill the pipeline.
  1042. Fetch(0);
  1043. // Fetch the next URL header data from the server.
  1044. switch (Server->RunHeaders())
  1045. {
  1046. case ServerState::RUN_HEADERS_OK:
  1047. break;
  1048. // The header data is bad
  1049. case ServerState::RUN_HEADERS_PARSE_ERROR:
  1050. {
  1051. _error->Error(_("Bad header data"));
  1052. Fail(true);
  1053. RotateDNS();
  1054. continue;
  1055. }
  1056. // The server closed a connection during the header get..
  1057. default:
  1058. case ServerState::RUN_HEADERS_IO_ERROR:
  1059. {
  1060. FailCounter++;
  1061. _error->Discard();
  1062. Server->Close();
  1063. Server->Pipeline = false;
  1064. if (FailCounter >= 2)
  1065. {
  1066. Fail(_("Connection failed"),true);
  1067. FailCounter = 0;
  1068. }
  1069. RotateDNS();
  1070. continue;
  1071. }
  1072. };
  1073. // Decide what to do.
  1074. FetchResult Res;
  1075. Res.Filename = Queue->DestFile;
  1076. switch (DealWithHeaders(Res,Server))
  1077. {
  1078. // Ok, the file is Open
  1079. case FILE_IS_OPEN:
  1080. {
  1081. URIStart(Res);
  1082. // Run the data
  1083. bool Result = Server->RunData();
  1084. /* If the server is sending back sizeless responses then fill in
  1085. the size now */
  1086. if (Res.Size == 0)
  1087. Res.Size = File->Size();
  1088. // Close the file, destroy the FD object and timestamp it
  1089. FailFd = -1;
  1090. delete File;
  1091. File = 0;
  1092. // Timestamp
  1093. struct utimbuf UBuf;
  1094. time(&UBuf.actime);
  1095. UBuf.actime = Server->Date;
  1096. UBuf.modtime = Server->Date;
  1097. utime(Queue->DestFile.c_str(),&UBuf);
  1098. // Send status to APT
  1099. if (Result == true)
  1100. {
  1101. Res.TakeHashes(*Server->In.Hash);
  1102. URIDone(Res);
  1103. }
  1104. else
  1105. {
  1106. if (Server->ServerFd == -1)
  1107. {
  1108. FailCounter++;
  1109. _error->Discard();
  1110. Server->Close();
  1111. if (FailCounter >= 2)
  1112. {
  1113. Fail(_("Connection failed"),true);
  1114. FailCounter = 0;
  1115. }
  1116. QueueBack = Queue;
  1117. }
  1118. else
  1119. Fail(true);
  1120. }
  1121. break;
  1122. }
  1123. // IMS hit
  1124. case IMS_HIT:
  1125. {
  1126. URIDone(Res);
  1127. break;
  1128. }
  1129. // Hard server error, not found or something
  1130. case ERROR_UNRECOVERABLE:
  1131. {
  1132. Fail();
  1133. break;
  1134. }
  1135. // Hard internal error, kill the connection and fail
  1136. case ERROR_NOT_FROM_SERVER:
  1137. {
  1138. delete File;
  1139. File = 0;
  1140. Fail();
  1141. RotateDNS();
  1142. Server->Close();
  1143. break;
  1144. }
  1145. // We need to flush the data, the header is like a 404 w/ error text
  1146. case ERROR_WITH_CONTENT_PAGE:
  1147. {
  1148. Fail();
  1149. // Send to content to dev/null
  1150. File = new FileFd("/dev/null",FileFd::WriteExists);
  1151. Server->RunData();
  1152. delete File;
  1153. File = 0;
  1154. break;
  1155. }
  1156. // Try again with a new URL
  1157. case TRY_AGAIN_OR_REDIRECT:
  1158. {
  1159. // Clear rest of response if there is content
  1160. if (Server->HaveContent)
  1161. {
  1162. File = new FileFd("/dev/null",FileFd::WriteExists);
  1163. Server->RunData();
  1164. delete File;
  1165. File = 0;
  1166. }
  1167. /* Detect redirect loops. No more redirects are allowed
  1168. after the same URI is seen twice in a queue item. */
  1169. StringVector &R = Redirected[Queue->DestFile];
  1170. bool StopRedirects = false;
  1171. if (R.size() == 0)
  1172. R.push_back(Queue->Uri);
  1173. else if (R[0] == "STOP" || R.size() > 10)
  1174. StopRedirects = true;
  1175. else
  1176. {
  1177. for (StringVectorIterator I = R.begin(); I != R.end(); ++I)
  1178. if (Queue->Uri == *I)
  1179. {
  1180. R[0] = "STOP";
  1181. break;
  1182. }
  1183. R.push_back(Queue->Uri);
  1184. }
  1185. if (StopRedirects == false)
  1186. Redirect(NextURI);
  1187. else
  1188. Fail();
  1189. break;
  1190. }
  1191. default:
  1192. Fail(_("Internal error"));
  1193. break;
  1194. }
  1195. FailCounter = 0;
  1196. }
  1197. return 0;
  1198. }
  1199. /*}}}*/
  1200. // HttpMethod::AutoDetectProxy - auto detect proxy /*{{{*/
  1201. // ---------------------------------------------------------------------
  1202. /* */
  1203. bool HttpMethod::AutoDetectProxy()
  1204. {
  1205. if (AutoDetectProxyCmd.empty())
  1206. return true;
  1207. if (Debug)
  1208. clog << "Using auto proxy detect command: " << AutoDetectProxyCmd << endl;
  1209. int Pipes[2] = {-1,-1};
  1210. if (pipe(Pipes) != 0)
  1211. return _error->Errno("pipe", "Failed to create Pipe");
  1212. pid_t Process = ExecFork();
  1213. if (Process == 0)
  1214. {
  1215. close(Pipes[0]);
  1216. dup2(Pipes[1],STDOUT_FILENO);
  1217. SetCloseExec(STDOUT_FILENO,false);
  1218. const char *Args[2];
  1219. Args[0] = AutoDetectProxyCmd.c_str();
  1220. Args[1] = 0;
  1221. execv(Args[0],(char **)Args);
  1222. cerr << "Failed to exec method " << Args[0] << endl;
  1223. _exit(100);
  1224. }
  1225. char buf[512];
  1226. int InFd = Pipes[0];
  1227. close(Pipes[1]);
  1228. int res = read(InFd, buf, sizeof(buf));
  1229. ExecWait(Process, "ProxyAutoDetect", true);
  1230. if (res < 0)
  1231. return _error->Errno("read", "Failed to read");
  1232. if (res == 0)
  1233. return _error->Warning("ProxyAutoDetect returned no data");
  1234. // add trailing \0
  1235. buf[res] = 0;
  1236. if (Debug)
  1237. clog << "auto detect command returned: '" << buf << "'" << endl;
  1238. if (strstr(buf, "http://") == buf)
  1239. _config->Set("Acquire::http::proxy", _strstrip(buf));
  1240. return true;
  1241. }
  1242. /*}}}*/