| 388 | } |
| 389 | } |
| 390 | void HttpRequestTest::testCreateRequest_with_cookie() |
| 391 | { |
| 392 | auto request = std::make_shared<Request>(); |
| 393 | request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2"); |
| 394 | auto p = std::make_shared<Piece>(0, 1_m); |
| 395 | auto segment = std::make_shared<PiecedSegment>(1_m, p); |
| 396 | auto fileEntry = std::make_shared<FileEntry>("file", 10_m, 0); |
| 397 | |
| 398 | auto st = CookieStorage{}; |
| 399 | CPPUNIT_ASSERT(st.store( |
| 400 | createCookie("name1", "value1", "localhost", true, "/archives", false), |
| 401 | 0)); |
| 402 | CPPUNIT_ASSERT(st.store(createCookie("name2", "value2", "localhost", true, |
| 403 | "/archives/download", false), |
| 404 | 0)); |
| 405 | CPPUNIT_ASSERT(st.store(createCookie("name3", "value3", "aria2.org", false, |
| 406 | "/archives/download", false), |
| 407 | 0)); |
| 408 | CPPUNIT_ASSERT(st.store( |
| 409 | createCookie("name4", "value4", "aria2.org", false, "/archives/", true), |
| 410 | 0)); |
| 411 | CPPUNIT_ASSERT(st.store( |
| 412 | createCookie("name5", "value5", "example.org", false, "/", false), 0)); |
| 413 | |
| 414 | HttpRequest httpRequest; |
| 415 | |
| 416 | httpRequest.disableContentEncoding(); |
| 417 | httpRequest.setRequest(request); |
| 418 | httpRequest.setSegment(segment); |
| 419 | httpRequest.setFileEntry(fileEntry); |
| 420 | httpRequest.setCookieStorage(&st); |
| 421 | httpRequest.setAuthConfigFactory(authConfigFactory_.get()); |
| 422 | httpRequest.setOption(option_.get()); |
| 423 | httpRequest.setNoWantDigest(true); |
| 424 | |
| 425 | std::string expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n" |
| 426 | "User-Agent: aria2\r\n" |
| 427 | "Accept: */*\r\n" |
| 428 | "Host: localhost\r\n" |
| 429 | "Pragma: no-cache\r\n" |
| 430 | "Cache-Control: no-cache\r\n" |
| 431 | "Connection: close\r\n" |
| 432 | "Cookie: name1=value1;\r\n" |
| 433 | "\r\n"; |
| 434 | |
| 435 | CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest()); |
| 436 | |
| 437 | request->setUri("http://localhost/archives/download/aria2-1.0.0.tar.bz2"); |
| 438 | |
| 439 | expectedText = "GET /archives/download/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n" |
| 440 | "User-Agent: aria2\r\n" |
| 441 | "Accept: */*\r\n" |
| 442 | "Host: localhost\r\n" |
| 443 | "Pragma: no-cache\r\n" |
| 444 | "Cache-Control: no-cache\r\n" |
| 445 | "Connection: close\r\n" |
| 446 | "Cookie: name2=value2;name1=value1;\r\n" |
| 447 | "\r\n"; |
nothing calls this directly
no test coverage detected