HttpRequestTest.cc 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. #include "HttpRequest.h"
  2. #include "prefs.h"
  3. #include "AuthConfigFactory.h"
  4. #include "PiecedSegment.h"
  5. #include "Piece.h"
  6. #include "Range.h"
  7. #include "Request.h"
  8. #include "CookieBox.h"
  9. #include "Option.h"
  10. #include <cppunit/extensions/HelperMacros.h>
  11. namespace aria2 {
  12. class HttpRequestTest : public CppUnit::TestFixture {
  13. CPPUNIT_TEST_SUITE(HttpRequestTest);
  14. CPPUNIT_TEST(testGetStartByte);
  15. CPPUNIT_TEST(testGetEndByte);
  16. CPPUNIT_TEST(testCreateRequest);
  17. CPPUNIT_TEST(testCreateRequest_ftp);
  18. CPPUNIT_TEST(testCreateRequest_with_cookie);
  19. CPPUNIT_TEST(testCreateProxyRequest);
  20. CPPUNIT_TEST(testIsRangeSatisfied);
  21. CPPUNIT_TEST(testUserAgent);
  22. CPPUNIT_TEST_SUITE_END();
  23. private:
  24. public:
  25. void setUp() {}
  26. void testGetStartByte();
  27. void testGetEndByte();
  28. void testCreateRequest();
  29. void testCreateRequest_ftp();
  30. void testCreateRequest_with_cookie();
  31. void testCreateProxyRequest();
  32. void testIsRangeSatisfied();
  33. void testUserAgent();
  34. };
  35. CPPUNIT_TEST_SUITE_REGISTRATION( HttpRequestTest );
  36. void HttpRequestTest::testGetStartByte()
  37. {
  38. HttpRequest httpRequest;
  39. SharedHandle<Piece> p(new Piece(1, 1024));
  40. SharedHandle<Segment> segment(new PiecedSegment(1024, p));
  41. CPPUNIT_ASSERT_EQUAL(0LL, httpRequest.getStartByte());
  42. httpRequest.setSegment(segment);
  43. CPPUNIT_ASSERT_EQUAL(1024LL, httpRequest.getStartByte());
  44. }
  45. void HttpRequestTest::testGetEndByte()
  46. {
  47. size_t index = 1;
  48. size_t length = 1024*1024-1024;
  49. size_t segmentLength = 1024*1024;
  50. HttpRequest httpRequest;
  51. SharedHandle<Piece> piece(new Piece(index, length));
  52. SharedHandle<Segment> segment(new PiecedSegment(segmentLength, piece));
  53. CPPUNIT_ASSERT_EQUAL(0LL, httpRequest.getEndByte());
  54. httpRequest.setSegment(segment);
  55. CPPUNIT_ASSERT_EQUAL(0LL, httpRequest.getEndByte());
  56. SharedHandle<Request> request(new Request());
  57. request->setKeepAlive(true);
  58. httpRequest.setRequest(request);
  59. CPPUNIT_ASSERT_EQUAL((off_t)segmentLength*index+length-1,
  60. httpRequest.getEndByte());
  61. request->setKeepAlive(false);
  62. CPPUNIT_ASSERT_EQUAL(0LL, httpRequest.getEndByte());
  63. }
  64. void HttpRequestTest::testCreateRequest()
  65. {
  66. SharedHandle<Piece> p;
  67. Option option;
  68. option.put(PREF_HTTP_AUTH_ENABLED, V_FALSE);
  69. option.put(PREF_HTTP_PROXY_ENABLED, V_FALSE);
  70. option.put(PREF_HTTP_PROXY_METHOD, V_TUNNEL);
  71. option.put(PREF_HTTP_PROXY_AUTH_ENABLED, V_FALSE);
  72. option.put(PREF_HTTP_USER, "aria2user");
  73. option.put(PREF_HTTP_PASSWD, "aria2passwd");
  74. option.put(PREF_HTTP_PROXY_USER, "aria2proxyuser");
  75. option.put(PREF_HTTP_PROXY_PASSWD, "aria2proxypasswd");
  76. SharedHandle<AuthConfigFactory> authConfigFactory(new AuthConfigFactory(&option));
  77. SingletonHolder<SharedHandle<AuthConfigFactory> >::instance(authConfigFactory);
  78. SharedHandle<Request> request(new Request());
  79. request->setUrl("http://localhost:8080/archives/aria2-1.0.0.tar.bz2");
  80. p.reset(new Piece(0, 1024));
  81. SharedHandle<Segment> segment(new PiecedSegment(1024, p));
  82. HttpRequest httpRequest;
  83. httpRequest.setRequest(request);
  84. httpRequest.setSegment(segment);
  85. request->setKeepAlive(true);
  86. std::string expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
  87. "User-Agent: aria2\r\n"
  88. "Accept: */*\r\n"
  89. "Host: localhost:8080\r\n"
  90. "Pragma: no-cache\r\n"
  91. "Cache-Control: no-cache\r\n"
  92. "Range: bytes=0-1023\r\n"
  93. "\r\n";
  94. CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
  95. request->setKeepAlive(false);
  96. expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
  97. "User-Agent: aria2\r\n"
  98. "Accept: */*\r\n"
  99. "Host: localhost:8080\r\n"
  100. "Pragma: no-cache\r\n"
  101. "Cache-Control: no-cache\r\n"
  102. "Connection: close\r\n"
  103. "\r\n";
  104. CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
  105. p.reset(new Piece(1, 1024*1024));
  106. segment.reset(new PiecedSegment(1024*1024, p));
  107. httpRequest.setSegment(segment);
  108. expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
  109. "User-Agent: aria2\r\n"
  110. "Accept: */*\r\n"
  111. "Host: localhost:8080\r\n"
  112. "Pragma: no-cache\r\n"
  113. "Cache-Control: no-cache\r\n"
  114. "Connection: close\r\n"
  115. "Range: bytes=1048576-\r\n"
  116. "\r\n";
  117. CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
  118. request->setKeepAlive(true);
  119. expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
  120. "User-Agent: aria2\r\n"
  121. "Accept: */*\r\n"
  122. "Host: localhost:8080\r\n"
  123. "Pragma: no-cache\r\n"
  124. "Cache-Control: no-cache\r\n"
  125. "Range: bytes=1048576-2097151\r\n"
  126. "\r\n";
  127. CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
  128. request->setKeepAlive(false);
  129. request->redirectUrl("http://localhost:8080/archives/download/aria2-1.0.0.tar.bz2");
  130. expectedText = "GET /archives/download/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
  131. "User-Agent: aria2\r\n"
  132. "Accept: */*\r\n"
  133. "Host: localhost:8080\r\n"
  134. "Pragma: no-cache\r\n"
  135. "Cache-Control: no-cache\r\n"
  136. "Connection: close\r\n"
  137. "Range: bytes=1048576-\r\n"
  138. "\r\n";
  139. CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
  140. request->resetUrl();
  141. p.reset(new Piece(0, 1024*1024));
  142. segment.reset(new PiecedSegment(1024*1024, p));
  143. httpRequest.setSegment(segment);
  144. // enable http auth
  145. option.put(PREF_HTTP_AUTH_ENABLED, V_TRUE);
  146. httpRequest.configure(&option);
  147. expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
  148. "User-Agent: aria2\r\n"
  149. "Accept: */*\r\n"
  150. "Host: localhost:8080\r\n"
  151. "Pragma: no-cache\r\n"
  152. "Cache-Control: no-cache\r\n"
  153. "Connection: close\r\n"
  154. "Authorization: Basic YXJpYTJ1c2VyOmFyaWEycGFzc3dk\r\n"
  155. "\r\n";
  156. CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
  157. // enable http proxy auth
  158. option.put(PREF_HTTP_PROXY_AUTH_ENABLED, V_TRUE);
  159. httpRequest.configure(&option);
  160. expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
  161. "User-Agent: aria2\r\n"
  162. "Accept: */*\r\n"
  163. "Host: localhost:8080\r\n"
  164. "Pragma: no-cache\r\n"
  165. "Cache-Control: no-cache\r\n"
  166. "Connection: close\r\n"
  167. "Authorization: Basic YXJpYTJ1c2VyOmFyaWEycGFzc3dk\r\n"
  168. "\r\n";
  169. CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
  170. option.put(PREF_HTTP_PROXY_ENABLED, V_TRUE);
  171. httpRequest.configure(&option);
  172. expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
  173. "User-Agent: aria2\r\n"
  174. "Accept: */*\r\n"
  175. "Host: localhost:8080\r\n"
  176. "Pragma: no-cache\r\n"
  177. "Cache-Control: no-cache\r\n"
  178. "Connection: close\r\n"
  179. "Authorization: Basic YXJpYTJ1c2VyOmFyaWEycGFzc3dk\r\n"
  180. "\r\n";
  181. CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
  182. option.put(PREF_HTTP_PROXY_METHOD, V_GET);
  183. httpRequest.configure(&option);
  184. expectedText = "GET http://localhost:8080/archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
  185. "User-Agent: aria2\r\n"
  186. "Accept: */*\r\n"
  187. "Host: localhost:8080\r\n"
  188. "Pragma: no-cache\r\n"
  189. "Cache-Control: no-cache\r\n"
  190. "Connection: close\r\n"
  191. "Proxy-Connection: close\r\n"
  192. "Proxy-Authorization: Basic YXJpYTJwcm94eXVzZXI6YXJpYTJwcm94eXBhc3N3ZA==\r\n"
  193. "Authorization: Basic YXJpYTJ1c2VyOmFyaWEycGFzc3dk\r\n"
  194. "\r\n";
  195. CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
  196. request->setKeepAlive(true);
  197. expectedText = "GET http://localhost:8080/archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
  198. "User-Agent: aria2\r\n"
  199. "Accept: */*\r\n"
  200. "Host: localhost:8080\r\n"
  201. "Pragma: no-cache\r\n"
  202. "Cache-Control: no-cache\r\n"
  203. "Range: bytes=0-1048575\r\n"
  204. "Proxy-Connection: Keep-Alive\r\n"
  205. "Proxy-Authorization: Basic YXJpYTJwcm94eXVzZXI6YXJpYTJwcm94eXBhc3N3ZA==\r\n"
  206. "Authorization: Basic YXJpYTJ1c2VyOmFyaWEycGFzc3dk\r\n"
  207. "\r\n";
  208. CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
  209. request->setKeepAlive(false);
  210. option.put(PREF_HTTP_PROXY_AUTH_ENABLED, V_FALSE);
  211. httpRequest.configure(&option);
  212. expectedText = "GET http://localhost:8080/archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
  213. "User-Agent: aria2\r\n"
  214. "Accept: */*\r\n"
  215. "Host: localhost:8080\r\n"
  216. "Pragma: no-cache\r\n"
  217. "Cache-Control: no-cache\r\n"
  218. "Connection: close\r\n"
  219. "Proxy-Connection: close\r\n"
  220. "Authorization: Basic YXJpYTJ1c2VyOmFyaWEycGFzc3dk\r\n"
  221. "\r\n";
  222. CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
  223. }
  224. void HttpRequestTest::testCreateRequest_ftp()
  225. {
  226. Option option;
  227. option.put(PREF_HTTP_AUTH_ENABLED, V_FALSE);
  228. option.put(PREF_HTTP_PROXY_ENABLED, V_FALSE);
  229. option.put(PREF_HTTP_PROXY_METHOD, V_TUNNEL);
  230. option.put(PREF_HTTP_PROXY_AUTH_ENABLED, V_FALSE);
  231. option.put(PREF_HTTP_USER, "aria2user");
  232. option.put(PREF_HTTP_PASSWD, "aria2passwd");
  233. option.put(PREF_HTTP_PROXY_USER, "aria2proxyuser");
  234. option.put(PREF_HTTP_PROXY_PASSWD, "aria2proxypasswd");
  235. SharedHandle<AuthConfigFactory> authConfigFactory
  236. (new AuthConfigFactory(&option));
  237. SingletonHolder<SharedHandle<AuthConfigFactory> >::instance(authConfigFactory);
  238. SharedHandle<Request> request(new Request());
  239. request->setUrl("ftp://localhost:8080/archives/aria2-1.0.0.tar.bz2");
  240. HttpRequest httpRequest;
  241. SharedHandle<Piece> p(new Piece(0, 1024*1024));
  242. SharedHandle<Segment> segment
  243. (new PiecedSegment(1024*1024, p));
  244. httpRequest.setRequest(request);
  245. httpRequest.setSegment(segment);
  246. httpRequest.configure(&option);
  247. std::string expectedText = "GET ftp://localhost:8080/archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
  248. "User-Agent: aria2\r\n"
  249. "Accept: */*\r\n"
  250. "Host: localhost:8080\r\n"
  251. "Pragma: no-cache\r\n"
  252. "Cache-Control: no-cache\r\n"
  253. "Connection: close\r\n"
  254. "\r\n";
  255. CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
  256. // How to enable HTTP proxy authorization in FTP download via HTTP proxy
  257. option.put(PREF_HTTP_PROXY_ENABLED, V_TRUE);
  258. option.put(PREF_HTTP_PROXY_METHOD, V_GET);
  259. option.put(PREF_HTTP_PROXY_AUTH_ENABLED, V_TRUE);
  260. httpRequest.configure(&option);
  261. expectedText = "GET ftp://localhost:8080/archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
  262. "User-Agent: aria2\r\n"
  263. "Accept: */*\r\n"
  264. "Host: localhost:8080\r\n"
  265. "Pragma: no-cache\r\n"
  266. "Cache-Control: no-cache\r\n"
  267. "Connection: close\r\n"
  268. "Proxy-Connection: close\r\n"
  269. "Proxy-Authorization: Basic YXJpYTJwcm94eXVzZXI6YXJpYTJwcm94eXBhc3N3ZA==\r\n"
  270. "\r\n";
  271. CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
  272. }
  273. void HttpRequestTest::testCreateRequest_with_cookie()
  274. {
  275. SharedHandle<Request> request(new Request());
  276. request->setUrl("http://localhost/archives/aria2-1.0.0.tar.bz2");
  277. SharedHandle<Piece> p(new Piece(0, 1024*1024));
  278. SharedHandle<Segment> segment
  279. (new PiecedSegment(1024*1024, p));
  280. Cookie cookie1("name1", "value1", "/archives", "localhost", false);
  281. Cookie cookie2("name2", "value2", "/archives/download", "localhost", false);
  282. Cookie cookie3("name3", "value3", "/archives/download", "tt.localhost", false);
  283. Cookie cookie4("name4", "value4", "/archives/download", "tt.localhost", true);
  284. request->cookieBox->add(cookie1);
  285. request->cookieBox->add(cookie2);
  286. request->cookieBox->add(cookie3);
  287. request->cookieBox->add(cookie4);
  288. HttpRequest httpRequest;
  289. httpRequest.setRequest(request);
  290. httpRequest.setSegment(segment);
  291. std::string expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
  292. "User-Agent: aria2\r\n"
  293. "Accept: */*\r\n"
  294. "Host: localhost\r\n"
  295. "Pragma: no-cache\r\n"
  296. "Cache-Control: no-cache\r\n"
  297. "Connection: close\r\n"
  298. "Cookie: name1=value1;\r\n"
  299. "\r\n";
  300. CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
  301. request->setUrl("http://localhost/archives/download/aria2-1.0.0.tar.bz2");
  302. expectedText = "GET /archives/download/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
  303. "User-Agent: aria2\r\n"
  304. "Accept: */*\r\n"
  305. "Host: localhost\r\n"
  306. "Pragma: no-cache\r\n"
  307. "Cache-Control: no-cache\r\n"
  308. "Connection: close\r\n"
  309. "Cookie: name1=value1;name2=value2;\r\n"
  310. "\r\n";
  311. CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
  312. request->setUrl("http://tt.localhost/archives/download/aria2-1.0.0.tar.bz2");
  313. expectedText = "GET /archives/download/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
  314. "User-Agent: aria2\r\n"
  315. "Accept: */*\r\n"
  316. "Host: tt.localhost\r\n"
  317. "Pragma: no-cache\r\n"
  318. "Cache-Control: no-cache\r\n"
  319. "Connection: close\r\n"
  320. "Cookie: name1=value1;name2=value2;name3=value3;\r\n"
  321. "\r\n";
  322. CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
  323. request->setUrl("https://tt.localhost/archives/download/aria2-1.0.0.tar.bz2");
  324. expectedText = "GET /archives/download/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
  325. "User-Agent: aria2\r\n"
  326. "Accept: */*\r\n"
  327. "Host: tt.localhost\r\n"
  328. "Pragma: no-cache\r\n"
  329. "Cache-Control: no-cache\r\n"
  330. "Connection: close\r\n"
  331. "Cookie: name1=value1;name2=value2;name3=value3;name4=value4;\r\n"
  332. "\r\n";
  333. CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
  334. }
  335. void HttpRequestTest::testCreateProxyRequest()
  336. {
  337. SharedHandle<Request> request(new Request());
  338. request->setUrl("http://localhost/archives/aria2-1.0.0.tar.bz2");
  339. SharedHandle<Piece> p(new Piece(0, 1024*1024));
  340. SharedHandle<Segment> segment(new PiecedSegment(1024*1024, p));
  341. HttpRequest httpRequest;
  342. httpRequest.setRequest(request);
  343. httpRequest.setSegment(segment);
  344. std::string expectedText = "CONNECT localhost:80 HTTP/1.1\r\n"
  345. "User-Agent: aria2\r\n"
  346. "Host: localhost:80\r\n"
  347. "Proxy-Connection: close\r\n"
  348. "\r\n";
  349. CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createProxyRequest());
  350. request->setKeepAlive(true);
  351. expectedText = "CONNECT localhost:80 HTTP/1.1\r\n"
  352. "User-Agent: aria2\r\n"
  353. "Host: localhost:80\r\n"
  354. "Proxy-Connection: Keep-Alive\r\n"
  355. "\r\n";
  356. CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createProxyRequest());
  357. }
  358. void HttpRequestTest::testIsRangeSatisfied()
  359. {
  360. SharedHandle<Request> request(new Request());
  361. request->setUrl("http://localhost:8080/archives/aria2-1.0.0.tar.bz2");
  362. request->setKeepAlive(false);
  363. SharedHandle<Piece> p(new Piece(0, 1024*1024));
  364. SharedHandle<Segment> segment(new PiecedSegment(1024*1024, p));
  365. HttpRequest httpRequest;
  366. httpRequest.setRequest(request);
  367. httpRequest.setSegment(segment);
  368. SharedHandle<Range> range(new Range());
  369. CPPUNIT_ASSERT(httpRequest.isRangeSatisfied(range));
  370. p.reset(new Piece(1, 1024*1024));
  371. segment.reset(new PiecedSegment(1024*1024, p));
  372. httpRequest.setSegment(segment);
  373. CPPUNIT_ASSERT(!httpRequest.isRangeSatisfied(range));
  374. uint64_t entityLength = segment->getSegmentLength()*10;
  375. range.reset(new Range(segment->getPosition(), 0, entityLength));
  376. CPPUNIT_ASSERT(httpRequest.isRangeSatisfied(range));
  377. httpRequest.setEntityLength(entityLength-1);
  378. CPPUNIT_ASSERT(!httpRequest.isRangeSatisfied(range));
  379. httpRequest.setEntityLength(entityLength);
  380. CPPUNIT_ASSERT(httpRequest.isRangeSatisfied(range));
  381. request->setKeepAlive(true);
  382. CPPUNIT_ASSERT(!httpRequest.isRangeSatisfied(range));
  383. range.reset(new Range(segment->getPosition(),
  384. segment->getPosition()+segment->getLength()-1,
  385. entityLength));
  386. CPPUNIT_ASSERT(httpRequest.isRangeSatisfied(range));
  387. range.reset(new Range(0, segment->getPosition()+segment->getLength()-1,
  388. entityLength));
  389. CPPUNIT_ASSERT(!httpRequest.isRangeSatisfied(range));
  390. }
  391. void HttpRequestTest::testUserAgent()
  392. {
  393. Option option;
  394. SharedHandle<AuthConfigFactory> authConfigFactory
  395. (new AuthConfigFactory(&option));
  396. SingletonHolder<SharedHandle<AuthConfigFactory> >::instance(authConfigFactory);
  397. SharedHandle<Request> request(new Request());
  398. request->setUrl("http://localhost:8080/archives/aria2-1.0.0.tar.bz2");
  399. SharedHandle<Piece> p(new Piece(0, 1024));
  400. SharedHandle<Segment> segment(new PiecedSegment(1024, p));
  401. HttpRequest httpRequest;
  402. httpRequest.setRequest(request);
  403. httpRequest.setSegment(segment);
  404. httpRequest.setUserAgent("aria2 (Linux)");
  405. std::string expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
  406. "User-Agent: aria2 (Linux)\r\n"
  407. "Accept: */*\r\n"
  408. "Host: localhost:8080\r\n"
  409. "Pragma: no-cache\r\n"
  410. "Cache-Control: no-cache\r\n"
  411. "Connection: close\r\n"
  412. "\r\n";
  413. CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
  414. std::string expectedTextForProxy = "CONNECT localhost:8080 HTTP/1.1\r\n"
  415. "User-Agent: aria2 (Linux)\r\n"
  416. "Host: localhost:8080\r\n"
  417. "Proxy-Connection: close\r\n"
  418. "\r\n";
  419. CPPUNIT_ASSERT_EQUAL(expectedTextForProxy, httpRequest.createProxyRequest());
  420. }
  421. } // namespace aria2