|
|
|
@ -106,10 +106,10 @@ void HttpResponseTest::testGetContentLength_contentLength()
|
|
|
|
|
{
|
|
|
|
|
HttpResponse httpResponse;
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
|
|
|
auto httpHeader = make_unique<HttpHeader>();
|
|
|
|
|
httpHeader->put(HttpHeader::CONTENT_LENGTH, "4294967296");
|
|
|
|
|
|
|
|
|
|
httpResponse.setHttpHeader(httpHeader);
|
|
|
|
|
httpResponse.setHttpHeader(std::move(httpHeader));
|
|
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL((int64_t)4294967296LL, httpResponse.getContentLength());
|
|
|
|
|
}
|
|
|
|
@ -118,15 +118,14 @@ void HttpResponseTest::testGetEntityLength()
|
|
|
|
|
{
|
|
|
|
|
HttpResponse httpResponse;
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
|
|
|
auto httpHeader = make_unique<HttpHeader>();
|
|
|
|
|
httpHeader->put(HttpHeader::CONTENT_LENGTH, "4294967296");
|
|
|
|
|
|
|
|
|
|
httpResponse.setHttpHeader(httpHeader);
|
|
|
|
|
|
|
|
|
|
httpResponse.setHttpHeader(std::move(httpHeader));
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL((int64_t)4294967296LL, httpResponse.getEntityLength());
|
|
|
|
|
|
|
|
|
|
httpHeader->put(HttpHeader::CONTENT_RANGE, "bytes 1-4294967296/4294967297");
|
|
|
|
|
|
|
|
|
|
httpResponse.getHttpHeader()->put(HttpHeader::CONTENT_RANGE,
|
|
|
|
|
"bytes 1-4294967296/4294967297");
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL((int64_t)4294967297LL, httpResponse.getEntityLength());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -134,10 +133,10 @@ void HttpResponseTest::testGetEntityLength()
|
|
|
|
|
void HttpResponseTest::testGetContentType()
|
|
|
|
|
{
|
|
|
|
|
HttpResponse httpResponse;
|
|
|
|
|
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
|
|
|
auto httpHeader = make_unique<HttpHeader>();
|
|
|
|
|
httpHeader->put(HttpHeader::CONTENT_TYPE,
|
|
|
|
|
"application/metalink+xml; charset=UTF-8");
|
|
|
|
|
httpResponse.setHttpHeader(httpHeader);
|
|
|
|
|
httpResponse.setHttpHeader(std::move(httpHeader));
|
|
|
|
|
// See paramter is ignored.
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("application/metalink+xml"),
|
|
|
|
|
httpResponse.getContentType());
|
|
|
|
@ -146,13 +145,12 @@ void HttpResponseTest::testGetContentType()
|
|
|
|
|
void HttpResponseTest::testDeterminFilename_without_ContentDisposition()
|
|
|
|
|
{
|
|
|
|
|
HttpResponse httpResponse;
|
|
|
|
|
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
|
|
|
std::shared_ptr<HttpRequest> httpRequest(new HttpRequest());
|
|
|
|
|
std::shared_ptr<Request> request(new Request());
|
|
|
|
|
request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2");
|
|
|
|
|
httpRequest->setRequest(request);
|
|
|
|
|
|
|
|
|
|
httpResponse.setHttpHeader(httpHeader);
|
|
|
|
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
|
|
|
|
httpResponse.setHttpRequest(httpRequest);
|
|
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("aria2-1.0.0.tar.bz2"),
|
|
|
|
@ -163,14 +161,14 @@ void HttpResponseTest::testDeterminFilename_with_ContentDisposition_zero_length
|
|
|
|
|
()
|
|
|
|
|
{
|
|
|
|
|
HttpResponse httpResponse;
|
|
|
|
|
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
|
|
|
auto httpHeader = make_unique<HttpHeader>();
|
|
|
|
|
httpHeader->put(HttpHeader::CONTENT_DISPOSITION, "attachment; filename=\"\"");
|
|
|
|
|
std::shared_ptr<HttpRequest> httpRequest(new HttpRequest());
|
|
|
|
|
std::shared_ptr<Request> request(new Request());
|
|
|
|
|
request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2");
|
|
|
|
|
httpRequest->setRequest(request);
|
|
|
|
|
|
|
|
|
|
httpResponse.setHttpHeader(httpHeader);
|
|
|
|
|
httpResponse.setHttpHeader(std::move(httpHeader));
|
|
|
|
|
httpResponse.setHttpRequest(httpRequest);
|
|
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("aria2-1.0.0.tar.bz2"),
|
|
|
|
@ -180,7 +178,7 @@ void HttpResponseTest::testDeterminFilename_with_ContentDisposition_zero_length
|
|
|
|
|
void HttpResponseTest::testDeterminFilename_with_ContentDisposition()
|
|
|
|
|
{
|
|
|
|
|
HttpResponse httpResponse;
|
|
|
|
|
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
|
|
|
auto httpHeader = make_unique<HttpHeader>();
|
|
|
|
|
httpHeader->put(HttpHeader::CONTENT_DISPOSITION,
|
|
|
|
|
"attachment; filename=\"aria2-current.tar.bz2\"");
|
|
|
|
|
std::shared_ptr<HttpRequest> httpRequest(new HttpRequest());
|
|
|
|
@ -188,7 +186,7 @@ void HttpResponseTest::testDeterminFilename_with_ContentDisposition()
|
|
|
|
|
request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2");
|
|
|
|
|
httpRequest->setRequest(request);
|
|
|
|
|
|
|
|
|
|
httpResponse.setHttpHeader(httpHeader);
|
|
|
|
|
httpResponse.setHttpHeader(std::move(httpHeader));
|
|
|
|
|
httpResponse.setHttpRequest(httpRequest);
|
|
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("aria2-current.tar.bz2"),
|
|
|
|
@ -198,9 +196,8 @@ void HttpResponseTest::testDeterminFilename_with_ContentDisposition()
|
|
|
|
|
void HttpResponseTest::testGetRedirectURI_without_Location()
|
|
|
|
|
{
|
|
|
|
|
HttpResponse httpResponse;
|
|
|
|
|
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
|
|
|
|
|
|
|
|
httpResponse.setHttpHeader(httpHeader);
|
|
|
|
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
|
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""),
|
|
|
|
|
httpResponse.getRedirectURI());
|
|
|
|
@ -209,9 +206,10 @@ void HttpResponseTest::testGetRedirectURI_without_Location()
|
|
|
|
|
void HttpResponseTest::testGetRedirectURI_with_Location()
|
|
|
|
|
{
|
|
|
|
|
HttpResponse httpResponse;
|
|
|
|
|
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
|
|
|
httpHeader->put(HttpHeader::LOCATION, "http://localhost/download/aria2-1.0.0.tar.bz2");
|
|
|
|
|
httpResponse.setHttpHeader(httpHeader);
|
|
|
|
|
auto httpHeader = make_unique<HttpHeader>();
|
|
|
|
|
httpHeader->put(HttpHeader::LOCATION,
|
|
|
|
|
"http://localhost/download/aria2-1.0.0.tar.bz2");
|
|
|
|
|
httpResponse.setHttpHeader(std::move(httpHeader));
|
|
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL
|
|
|
|
|
(std::string("http://localhost/download/aria2-1.0.0.tar.bz2"),
|
|
|
|
@ -221,45 +219,37 @@ void HttpResponseTest::testGetRedirectURI_with_Location()
|
|
|
|
|
void HttpResponseTest::testIsRedirect()
|
|
|
|
|
{
|
|
|
|
|
HttpResponse httpResponse;
|
|
|
|
|
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
|
|
|
auto httpHeader = make_unique<HttpHeader>();
|
|
|
|
|
httpHeader->setStatusCode(200);
|
|
|
|
|
httpHeader->put(HttpHeader::LOCATION,
|
|
|
|
|
"http://localhost/download/aria2-1.0.0.tar.bz2");
|
|
|
|
|
|
|
|
|
|
httpResponse.setHttpHeader(httpHeader);
|
|
|
|
|
|
|
|
|
|
httpResponse.setHttpHeader(std::move(httpHeader));
|
|
|
|
|
CPPUNIT_ASSERT(!httpResponse.isRedirect());
|
|
|
|
|
|
|
|
|
|
httpHeader->setStatusCode(301);
|
|
|
|
|
|
|
|
|
|
httpResponse.getHttpHeader()->setStatusCode(301);
|
|
|
|
|
CPPUNIT_ASSERT(httpResponse.isRedirect());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HttpResponseTest::testIsTransferEncodingSpecified()
|
|
|
|
|
{
|
|
|
|
|
HttpResponse httpResponse;
|
|
|
|
|
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
|
|
|
|
|
|
|
|
httpResponse.setHttpHeader(httpHeader);
|
|
|
|
|
|
|
|
|
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
|
|
|
|
CPPUNIT_ASSERT(!httpResponse.isTransferEncodingSpecified());
|
|
|
|
|
|
|
|
|
|
httpHeader->put(HttpHeader::TRANSFER_ENCODING, "chunked");
|
|
|
|
|
|
|
|
|
|
httpResponse.getHttpHeader()->put(HttpHeader::TRANSFER_ENCODING, "chunked");
|
|
|
|
|
CPPUNIT_ASSERT(httpResponse.isTransferEncodingSpecified());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HttpResponseTest::testGetTransferEncoding()
|
|
|
|
|
{
|
|
|
|
|
HttpResponse httpResponse;
|
|
|
|
|
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
|
|
|
|
|
|
|
|
httpResponse.setHttpHeader(httpHeader);
|
|
|
|
|
|
|
|
|
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), httpResponse.getTransferEncoding());
|
|
|
|
|
|
|
|
|
|
httpHeader->put(HttpHeader::TRANSFER_ENCODING, "chunked");
|
|
|
|
|
|
|
|
|
|
httpResponse.getHttpHeader()->put(HttpHeader::TRANSFER_ENCODING, "chunked");
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("chunked"),
|
|
|
|
|
httpResponse.getTransferEncoding());
|
|
|
|
|
}
|
|
|
|
@ -267,56 +257,45 @@ void HttpResponseTest::testGetTransferEncoding()
|
|
|
|
|
void HttpResponseTest::testGetTransferEncodingStreamFilter()
|
|
|
|
|
{
|
|
|
|
|
HttpResponse httpResponse;
|
|
|
|
|
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
|
|
|
|
|
|
|
|
httpResponse.setHttpHeader(httpHeader);
|
|
|
|
|
|
|
|
|
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
|
|
|
|
CPPUNIT_ASSERT(!httpResponse.getTransferEncodingStreamFilter());
|
|
|
|
|
|
|
|
|
|
httpHeader->put(HttpHeader::TRANSFER_ENCODING, "chunked");
|
|
|
|
|
|
|
|
|
|
httpResponse.getHttpHeader()->put(HttpHeader::TRANSFER_ENCODING, "chunked");
|
|
|
|
|
CPPUNIT_ASSERT(httpResponse.getTransferEncodingStreamFilter());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HttpResponseTest::testIsContentEncodingSpecified()
|
|
|
|
|
{
|
|
|
|
|
HttpResponse httpResponse;
|
|
|
|
|
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
|
|
|
|
|
|
|
|
httpResponse.setHttpHeader(httpHeader);
|
|
|
|
|
|
|
|
|
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
|
|
|
|
CPPUNIT_ASSERT(!httpResponse.isContentEncodingSpecified());
|
|
|
|
|
|
|
|
|
|
httpHeader->put(HttpHeader::CONTENT_ENCODING, "gzip");
|
|
|
|
|
|
|
|
|
|
httpResponse.getHttpHeader()->put(HttpHeader::CONTENT_ENCODING, "gzip");
|
|
|
|
|
CPPUNIT_ASSERT(httpResponse.isContentEncodingSpecified());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HttpResponseTest::testGetContentEncoding()
|
|
|
|
|
{
|
|
|
|
|
HttpResponse httpResponse;
|
|
|
|
|
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
|
|
|
|
|
|
|
|
httpResponse.setHttpHeader(httpHeader);
|
|
|
|
|
|
|
|
|
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(A2STR::NIL, httpResponse.getContentEncoding());
|
|
|
|
|
|
|
|
|
|
httpHeader->put(HttpHeader::CONTENT_ENCODING, "gzip");
|
|
|
|
|
|
|
|
|
|
httpResponse.getHttpHeader()->put(HttpHeader::CONTENT_ENCODING, "gzip");
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("gzip"), httpResponse.getContentEncoding());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HttpResponseTest::testGetContentEncodingStreamFilter()
|
|
|
|
|
{
|
|
|
|
|
HttpResponse httpResponse;
|
|
|
|
|
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
|
|
|
|
|
|
|
|
httpResponse.setHttpHeader(httpHeader);
|
|
|
|
|
|
|
|
|
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
|
|
|
|
CPPUNIT_ASSERT(!httpResponse.getContentEncodingStreamFilter());
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_ZLIB
|
|
|
|
|
httpHeader->put(HttpHeader::CONTENT_ENCODING, "gzip");
|
|
|
|
|
httpResponse.getHttpHeader()->put(HttpHeader::CONTENT_ENCODING, "gzip");
|
|
|
|
|
{
|
|
|
|
|
std::shared_ptr<StreamFilter> filter =
|
|
|
|
|
httpResponse.getContentEncodingStreamFilter();
|
|
|
|
@ -324,9 +303,8 @@ void HttpResponseTest::testGetContentEncodingStreamFilter()
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("GZipDecodingStreamFilter"),
|
|
|
|
|
filter->getName());
|
|
|
|
|
}
|
|
|
|
|
httpHeader.reset(new HttpHeader());
|
|
|
|
|
httpResponse.setHttpHeader(httpHeader);
|
|
|
|
|
httpHeader->put(HttpHeader::CONTENT_ENCODING, "deflate");
|
|
|
|
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
|
|
|
|
httpResponse.getHttpHeader()->put(HttpHeader::CONTENT_ENCODING, "deflate");
|
|
|
|
|
{
|
|
|
|
|
std::shared_ptr<StreamFilter> filter =
|
|
|
|
|
httpResponse.getContentEncodingStreamFilter();
|
|
|
|
@ -335,9 +313,8 @@ void HttpResponseTest::testGetContentEncodingStreamFilter()
|
|
|
|
|
filter->getName());
|
|
|
|
|
}
|
|
|
|
|
#endif // HAVE_ZLIB
|
|
|
|
|
httpHeader.reset(new HttpHeader());
|
|
|
|
|
httpResponse.setHttpHeader(httpHeader);
|
|
|
|
|
httpHeader->put(HttpHeader::CONTENT_ENCODING, "bzip2");
|
|
|
|
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
|
|
|
|
httpResponse.getHttpHeader()->put(HttpHeader::CONTENT_ENCODING, "bzip2");
|
|
|
|
|
{
|
|
|
|
|
std::shared_ptr<StreamFilter> filter =
|
|
|
|
|
httpResponse.getContentEncodingStreamFilter();
|
|
|
|
@ -348,10 +325,8 @@ void HttpResponseTest::testGetContentEncodingStreamFilter()
|
|
|
|
|
void HttpResponseTest::testValidateResponse()
|
|
|
|
|
{
|
|
|
|
|
HttpResponse httpResponse;
|
|
|
|
|
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
|
|
|
httpResponse.setHttpHeader(httpHeader);
|
|
|
|
|
|
|
|
|
|
httpHeader->setStatusCode(301);
|
|
|
|
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
|
|
|
|
httpResponse.getHttpHeader()->setStatusCode(301);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
httpResponse.validateResponse();
|
|
|
|
@ -359,8 +334,9 @@ void HttpResponseTest::testValidateResponse()
|
|
|
|
|
} catch(Exception& e) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
httpHeader->put(HttpHeader::LOCATION,
|
|
|
|
|
"http://localhost/archives/aria2-1.0.0.tar.bz2");
|
|
|
|
|
httpResponse.getHttpHeader()->put
|
|
|
|
|
(HttpHeader::LOCATION,
|
|
|
|
|
"http://localhost/archives/aria2-1.0.0.tar.bz2");
|
|
|
|
|
try {
|
|
|
|
|
httpResponse.validateResponse();
|
|
|
|
|
} catch(Exception& e) {
|
|
|
|
@ -371,8 +347,8 @@ void HttpResponseTest::testValidateResponse()
|
|
|
|
|
void HttpResponseTest::testValidateResponse_good_range()
|
|
|
|
|
{
|
|
|
|
|
HttpResponse httpResponse;
|
|
|
|
|
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
|
|
|
httpResponse.setHttpHeader(httpHeader);
|
|
|
|
|
|
|
|
|
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<HttpRequest> httpRequest(new HttpRequest());
|
|
|
|
|
std::shared_ptr<Piece> p(new Piece(1, 1024*1024));
|
|
|
|
@ -384,8 +360,9 @@ void HttpResponseTest::testValidateResponse_good_range()
|
|
|
|
|
request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2");
|
|
|
|
|
httpRequest->setRequest(request);
|
|
|
|
|
httpResponse.setHttpRequest(httpRequest);
|
|
|
|
|
httpHeader->setStatusCode(206);
|
|
|
|
|
httpHeader->put(HttpHeader::CONTENT_RANGE, "bytes 1048576-10485760/10485760");
|
|
|
|
|
httpResponse.getHttpHeader()->setStatusCode(206);
|
|
|
|
|
httpResponse.getHttpHeader()->put(HttpHeader::CONTENT_RANGE,
|
|
|
|
|
"bytes 1048576-10485760/10485760");
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
httpResponse.validateResponse();
|
|
|
|
@ -398,8 +375,8 @@ void HttpResponseTest::testValidateResponse_good_range()
|
|
|
|
|
void HttpResponseTest::testValidateResponse_bad_range()
|
|
|
|
|
{
|
|
|
|
|
HttpResponse httpResponse;
|
|
|
|
|
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
|
|
|
httpResponse.setHttpHeader(httpHeader);
|
|
|
|
|
|
|
|
|
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<HttpRequest> httpRequest(new HttpRequest());
|
|
|
|
|
std::shared_ptr<Piece> p(new Piece(1, 1024*1024));
|
|
|
|
@ -411,8 +388,9 @@ void HttpResponseTest::testValidateResponse_bad_range()
|
|
|
|
|
request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2");
|
|
|
|
|
httpRequest->setRequest(request);
|
|
|
|
|
httpResponse.setHttpRequest(httpRequest);
|
|
|
|
|
httpHeader->setStatusCode(206);
|
|
|
|
|
httpHeader->put(HttpHeader::CONTENT_RANGE, "bytes 0-10485760/10485761");
|
|
|
|
|
httpResponse.getHttpHeader()->setStatusCode(206);
|
|
|
|
|
httpResponse.getHttpHeader()->put(HttpHeader::CONTENT_RANGE,
|
|
|
|
|
"bytes 0-10485760/10485761");
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
httpResponse.validateResponse();
|
|
|
|
@ -424,8 +402,7 @@ void HttpResponseTest::testValidateResponse_bad_range()
|
|
|
|
|
void HttpResponseTest::testValidateResponse_chunked()
|
|
|
|
|
{
|
|
|
|
|
HttpResponse httpResponse;
|
|
|
|
|
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
|
|
|
httpResponse.setHttpHeader(httpHeader);
|
|
|
|
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<HttpRequest> httpRequest(new HttpRequest());
|
|
|
|
|
std::shared_ptr<Piece> p(new Piece(1, 1024*1024));
|
|
|
|
@ -437,9 +414,10 @@ void HttpResponseTest::testValidateResponse_chunked()
|
|
|
|
|
request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2");
|
|
|
|
|
httpRequest->setRequest(request);
|
|
|
|
|
httpResponse.setHttpRequest(httpRequest);
|
|
|
|
|
httpHeader->setStatusCode(206);
|
|
|
|
|
httpHeader->put(HttpHeader::CONTENT_RANGE, "bytes 0-10485760/10485761");
|
|
|
|
|
httpHeader->put(HttpHeader::TRANSFER_ENCODING, "chunked");
|
|
|
|
|
httpResponse.getHttpHeader()->setStatusCode(206);
|
|
|
|
|
httpResponse.getHttpHeader()->put(HttpHeader::CONTENT_RANGE,
|
|
|
|
|
"bytes 0-10485760/10485761");
|
|
|
|
|
httpResponse.getHttpHeader()->put(HttpHeader::TRANSFER_ENCODING, "chunked");
|
|
|
|
|
|
|
|
|
|
// if transfer-encoding is specified, then range validation is skipped.
|
|
|
|
|
try {
|
|
|
|
@ -452,9 +430,8 @@ void HttpResponseTest::testValidateResponse_chunked()
|
|
|
|
|
void HttpResponseTest::testValidateResponse_withIfModifiedSince()
|
|
|
|
|
{
|
|
|
|
|
HttpResponse httpResponse;
|
|
|
|
|
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
|
|
|
httpResponse.setHttpHeader(httpHeader);
|
|
|
|
|
httpHeader->setStatusCode(304);
|
|
|
|
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
|
|
|
|
httpResponse.getHttpHeader()->setStatusCode(304);
|
|
|
|
|
std::shared_ptr<HttpRequest> httpRequest(new HttpRequest());
|
|
|
|
|
httpResponse.setHttpRequest(httpRequest);
|
|
|
|
|
try {
|
|
|
|
@ -469,8 +446,8 @@ void HttpResponseTest::testValidateResponse_withIfModifiedSince()
|
|
|
|
|
void HttpResponseTest::testProcessRedirect()
|
|
|
|
|
{
|
|
|
|
|
HttpResponse httpResponse;
|
|
|
|
|
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
|
|
|
httpResponse.setHttpHeader(httpHeader);
|
|
|
|
|
|
|
|
|
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<HttpRequest> httpRequest(new HttpRequest());
|
|
|
|
|
std::shared_ptr<Request> request(new Request());
|
|
|
|
@ -478,22 +455,24 @@ void HttpResponseTest::testProcessRedirect()
|
|
|
|
|
httpRequest->setRequest(request);
|
|
|
|
|
httpResponse.setHttpRequest(httpRequest);
|
|
|
|
|
|
|
|
|
|
httpHeader->put(HttpHeader::LOCATION, "http://mirror/aria2-1.0.0.tar.bz2");
|
|
|
|
|
httpResponse.getHttpHeader()->put(HttpHeader::LOCATION,
|
|
|
|
|
"http://mirror/aria2-1.0.0.tar.bz2");
|
|
|
|
|
httpResponse.processRedirect();
|
|
|
|
|
|
|
|
|
|
httpHeader->clearField();
|
|
|
|
|
httpResponse.getHttpHeader()->clearField();
|
|
|
|
|
|
|
|
|
|
// Test for percent-encode
|
|
|
|
|
httpHeader->put(HttpHeader::LOCATION, "http://example.org/white space#aria2");
|
|
|
|
|
httpResponse.getHttpHeader()->put(HttpHeader::LOCATION,
|
|
|
|
|
"http://example.org/white space#aria2");
|
|
|
|
|
httpResponse.processRedirect();
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("http://example.org/white%20space"),
|
|
|
|
|
request->getCurrentUri());
|
|
|
|
|
|
|
|
|
|
httpHeader->clearField();
|
|
|
|
|
httpResponse.getHttpHeader()->clearField();
|
|
|
|
|
|
|
|
|
|
// Give unsupported scheme
|
|
|
|
|
httpHeader->put(HttpHeader::LOCATION,
|
|
|
|
|
"unsupported://mirror/aria2-1.0.0.tar.bz2");
|
|
|
|
|
httpResponse.getHttpHeader()->put
|
|
|
|
|
(HttpHeader::LOCATION, "unsupported://mirror/aria2-1.0.0.tar.bz2");
|
|
|
|
|
try {
|
|
|
|
|
httpResponse.processRedirect();
|
|
|
|
|
CPPUNIT_FAIL("DlRetryEx exception must be thrown.");
|
|
|
|
@ -507,8 +486,8 @@ void HttpResponseTest::testProcessRedirect()
|
|
|
|
|
void HttpResponseTest::testRetrieveCookie()
|
|
|
|
|
{
|
|
|
|
|
HttpResponse httpResponse;
|
|
|
|
|
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
|
|
|
httpResponse.setHttpHeader(httpHeader);
|
|
|
|
|
|
|
|
|
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<HttpRequest> httpRequest(new HttpRequest());
|
|
|
|
|
std::shared_ptr<Request> request(new Request());
|
|
|
|
@ -518,13 +497,15 @@ void HttpResponseTest::testRetrieveCookie()
|
|
|
|
|
httpRequest->setCookieStorage(&st);
|
|
|
|
|
httpResponse.setHttpRequest(httpRequest);
|
|
|
|
|
|
|
|
|
|
httpHeader->put(HttpHeader::SET_COOKIE,
|
|
|
|
|
"k1=v1; expires=Sun, 10-Jun-2007 11:00:00 GMT;"
|
|
|
|
|
"path=/; domain=.aria2.org;");
|
|
|
|
|
httpHeader->put(HttpHeader::SET_COOKIE,
|
|
|
|
|
"k2=v2; expires=Sun, 01-Jan-38 00:00:00 GMT;"
|
|
|
|
|
"path=/; domain=.aria2.org;");
|
|
|
|
|
httpHeader->put(HttpHeader::SET_COOKIE, "k3=v3;");
|
|
|
|
|
httpResponse.getHttpHeader()->put
|
|
|
|
|
(HttpHeader::SET_COOKIE,
|
|
|
|
|
"k1=v1; expires=Sun, 10-Jun-2007 11:00:00 GMT;"
|
|
|
|
|
"path=/; domain=.aria2.org;");
|
|
|
|
|
httpResponse.getHttpHeader()->put
|
|
|
|
|
(HttpHeader::SET_COOKIE,
|
|
|
|
|
"k2=v2; expires=Sun, 01-Jan-38 00:00:00 GMT;"
|
|
|
|
|
"path=/; domain=.aria2.org;");
|
|
|
|
|
httpResponse.getHttpHeader()->put(HttpHeader::SET_COOKIE, "k3=v3;");
|
|
|
|
|
|
|
|
|
|
httpResponse.retrieveCookie();
|
|
|
|
|
|
|
|
|
@ -539,69 +520,78 @@ void HttpResponseTest::testRetrieveCookie()
|
|
|
|
|
void HttpResponseTest::testSupportsPersistentConnection()
|
|
|
|
|
{
|
|
|
|
|
HttpResponse httpResponse;
|
|
|
|
|
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
|
|
|
httpResponse.setHttpHeader(httpHeader);
|
|
|
|
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
|
|
|
|
std::shared_ptr<HttpRequest> httpRequest(new HttpRequest());
|
|
|
|
|
httpResponse.setHttpRequest(httpRequest);
|
|
|
|
|
|
|
|
|
|
httpHeader->setVersion("HTTP/1.1");
|
|
|
|
|
httpResponse.getHttpHeader()->setVersion("HTTP/1.1");
|
|
|
|
|
CPPUNIT_ASSERT(httpResponse.supportsPersistentConnection());
|
|
|
|
|
httpHeader->put(HttpHeader::CONNECTION, "close");
|
|
|
|
|
httpResponse.getHttpHeader()->put(HttpHeader::CONNECTION, "close");
|
|
|
|
|
CPPUNIT_ASSERT(!httpResponse.supportsPersistentConnection());
|
|
|
|
|
httpHeader->clearField();
|
|
|
|
|
httpHeader->put(HttpHeader::CONNECTION, "keep-alive");
|
|
|
|
|
httpResponse.getHttpHeader()->clearField();
|
|
|
|
|
httpResponse.getHttpHeader()->put(HttpHeader::CONNECTION, "keep-alive");
|
|
|
|
|
CPPUNIT_ASSERT(httpResponse.supportsPersistentConnection());
|
|
|
|
|
httpHeader->clearField();
|
|
|
|
|
httpResponse.getHttpHeader()->clearField();
|
|
|
|
|
|
|
|
|
|
httpHeader->setVersion("HTTP/1.0");
|
|
|
|
|
httpResponse.getHttpHeader()->setVersion("HTTP/1.0");
|
|
|
|
|
CPPUNIT_ASSERT(!httpResponse.supportsPersistentConnection());
|
|
|
|
|
httpHeader->put(HttpHeader::CONNECTION, "close");
|
|
|
|
|
httpResponse.getHttpHeader()->put(HttpHeader::CONNECTION, "close");
|
|
|
|
|
CPPUNIT_ASSERT(!httpResponse.supportsPersistentConnection());
|
|
|
|
|
httpHeader->clearField();
|
|
|
|
|
httpHeader->put(HttpHeader::CONNECTION, "keep-alive");
|
|
|
|
|
httpResponse.getHttpHeader()->clearField();
|
|
|
|
|
httpResponse.getHttpHeader()->put(HttpHeader::CONNECTION, "keep-alive");
|
|
|
|
|
CPPUNIT_ASSERT(httpResponse.supportsPersistentConnection());
|
|
|
|
|
httpHeader->clearField();
|
|
|
|
|
httpResponse.getHttpHeader()->clearField();
|
|
|
|
|
|
|
|
|
|
// test proxy connection
|
|
|
|
|
std::shared_ptr<Request> proxyRequest(new Request());
|
|
|
|
|
httpRequest->setProxyRequest(proxyRequest);
|
|
|
|
|
|
|
|
|
|
httpHeader->setVersion("HTTP/1.1");
|
|
|
|
|
httpResponse.getHttpHeader()->setVersion("HTTP/1.1");
|
|
|
|
|
CPPUNIT_ASSERT(httpResponse.supportsPersistentConnection());
|
|
|
|
|
httpHeader->put(HttpHeader::CONNECTION, "close");
|
|
|
|
|
httpResponse.getHttpHeader()->put(HttpHeader::CONNECTION, "close");
|
|
|
|
|
CPPUNIT_ASSERT(!httpResponse.supportsPersistentConnection());
|
|
|
|
|
httpHeader->clearField();
|
|
|
|
|
httpHeader->put(HttpHeader::CONNECTION, "keep-alive");
|
|
|
|
|
httpResponse.getHttpHeader()->clearField();
|
|
|
|
|
httpResponse.getHttpHeader()->put(HttpHeader::CONNECTION, "keep-alive");
|
|
|
|
|
CPPUNIT_ASSERT(httpResponse.supportsPersistentConnection());
|
|
|
|
|
httpHeader->clearField();
|
|
|
|
|
httpResponse.getHttpHeader()->clearField();
|
|
|
|
|
|
|
|
|
|
httpHeader->setVersion("HTTP/1.0");
|
|
|
|
|
httpResponse.getHttpHeader()->setVersion("HTTP/1.0");
|
|
|
|
|
CPPUNIT_ASSERT(!httpResponse.supportsPersistentConnection());
|
|
|
|
|
httpHeader->put(HttpHeader::CONNECTION, "close");
|
|
|
|
|
httpResponse.getHttpHeader()->put(HttpHeader::CONNECTION, "close");
|
|
|
|
|
CPPUNIT_ASSERT(!httpResponse.supportsPersistentConnection());
|
|
|
|
|
httpHeader->clearField();
|
|
|
|
|
httpHeader->put(HttpHeader::CONNECTION, "keep-alive");
|
|
|
|
|
httpResponse.getHttpHeader()->clearField();
|
|
|
|
|
httpResponse.getHttpHeader()->put(HttpHeader::CONNECTION, "keep-alive");
|
|
|
|
|
CPPUNIT_ASSERT(httpResponse.supportsPersistentConnection());
|
|
|
|
|
httpHeader->clearField();
|
|
|
|
|
httpResponse.getHttpHeader()->clearField();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HttpResponseTest::testGetMetalinKHttpEntries()
|
|
|
|
|
{
|
|
|
|
|
HttpResponse httpResponse;
|
|
|
|
|
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
|
|
|
httpResponse.setHttpHeader(httpHeader);
|
|
|
|
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
|
|
|
|
std::shared_ptr<Option> option(new Option());
|
|
|
|
|
|
|
|
|
|
httpHeader->put(HttpHeader::LINK,
|
|
|
|
|
"<http://uri1/>; rel=duplicate; pri=1; pref; geo=JP");
|
|
|
|
|
httpHeader->put(HttpHeader::LINK,
|
|
|
|
|
"<http://uri2/>; rel=duplicate");
|
|
|
|
|
httpHeader->put(HttpHeader::LINK,
|
|
|
|
|
"<http://uri3/>;;;;;;;;rel=duplicate;;;;;pri=2;;;;;");
|
|
|
|
|
httpHeader->put(HttpHeader::LINK, "<http://uri4/>;rel=duplicate;=pri=1;pref");
|
|
|
|
|
httpHeader->put(HttpHeader::LINK, "<http://describedby>; rel=describedby");
|
|
|
|
|
httpHeader->put(HttpHeader::LINK, "<http://norel/>");
|
|
|
|
|
httpHeader->put(HttpHeader::LINK, "<baduri>; rel=duplicate; pri=-1;");
|
|
|
|
|
httpResponse.getHttpHeader()->put
|
|
|
|
|
(HttpHeader::LINK,
|
|
|
|
|
"<http://uri1/>; rel=duplicate; pri=1; pref; geo=JP");
|
|
|
|
|
httpResponse.getHttpHeader()->put
|
|
|
|
|
(HttpHeader::LINK,
|
|
|
|
|
"<http://uri2/>; rel=duplicate");
|
|
|
|
|
httpResponse.getHttpHeader()->put
|
|
|
|
|
(HttpHeader::LINK,
|
|
|
|
|
"<http://uri3/>;;;;;;;;rel=duplicate;;;;;pri=2;;;;;");
|
|
|
|
|
httpResponse.getHttpHeader()->put
|
|
|
|
|
(HttpHeader::LINK,
|
|
|
|
|
"<http://uri4/>;rel=duplicate;=pri=1;pref");
|
|
|
|
|
httpResponse.getHttpHeader()->put
|
|
|
|
|
(HttpHeader::LINK,
|
|
|
|
|
"<http://describedby>; rel=describedby");
|
|
|
|
|
httpResponse.getHttpHeader()->put
|
|
|
|
|
(HttpHeader::LINK,
|
|
|
|
|
"<http://norel/>");
|
|
|
|
|
httpResponse.getHttpHeader()->put
|
|
|
|
|
(HttpHeader::LINK,
|
|
|
|
|
"<baduri>; rel=duplicate; pri=-1;");
|
|
|
|
|
std::vector<MetalinkHttpEntry> result;
|
|
|
|
|
httpResponse.getMetalinKHttpEntries(result, option);
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)5, result.size());
|
|
|
|
@ -641,20 +631,23 @@ void HttpResponseTest::testGetMetalinKHttpEntries()
|
|
|
|
|
void HttpResponseTest::testGetDigest()
|
|
|
|
|
{
|
|
|
|
|
HttpResponse httpResponse;
|
|
|
|
|
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
|
|
|
httpResponse.setHttpHeader(httpHeader);
|
|
|
|
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
|
|
|
|
std::shared_ptr<Option> option(new Option());
|
|
|
|
|
// Python binascii.hexlify(base64.b64decode(B64ED_HASH)) is handy to
|
|
|
|
|
// retrieve ascii hex hash string.
|
|
|
|
|
httpHeader->put(HttpHeader::DIGEST, "SHA-1=82AD8itGL/oYQ5BTPFANiYnp9oE=");
|
|
|
|
|
httpHeader->put(HttpHeader::DIGEST, "NOT_SUPPORTED");
|
|
|
|
|
httpHeader->put(HttpHeader::DIGEST,
|
|
|
|
|
"SHA-224=rQdowoLHQJTMVZ3rF7vmYOIzUXlu7F+FcMbPnA==");
|
|
|
|
|
httpHeader->put(HttpHeader::DIGEST,
|
|
|
|
|
"SHA-224=6Ik6LNZ1iPy6cbmlKO4NHfvxzaiurmHilMyhGA==");
|
|
|
|
|
httpHeader->put(HttpHeader::DIGEST,
|
|
|
|
|
"SHA-256=+D8nGudz3G/kpkVKQeDrI3xD57v0UeQmzGCZOk03nsU=,"
|
|
|
|
|
"MD5=LJDK2+9ClF8Nz/K5WZd/+A==");
|
|
|
|
|
httpResponse.getHttpHeader()->put(HttpHeader::DIGEST,
|
|
|
|
|
"SHA-1=82AD8itGL/oYQ5BTPFANiYnp9oE=");
|
|
|
|
|
httpResponse.getHttpHeader()->put(HttpHeader::DIGEST, "NOT_SUPPORTED");
|
|
|
|
|
httpResponse.getHttpHeader()->put
|
|
|
|
|
(HttpHeader::DIGEST,
|
|
|
|
|
"SHA-224=rQdowoLHQJTMVZ3rF7vmYOIzUXlu7F+FcMbPnA==");
|
|
|
|
|
httpResponse.getHttpHeader()->put
|
|
|
|
|
(HttpHeader::DIGEST,
|
|
|
|
|
"SHA-224=6Ik6LNZ1iPy6cbmlKO4NHfvxzaiurmHilMyhGA==");
|
|
|
|
|
httpResponse.getHttpHeader()->put
|
|
|
|
|
(HttpHeader::DIGEST,
|
|
|
|
|
"SHA-256=+D8nGudz3G/kpkVKQeDrI3xD57v0UeQmzGCZOk03nsU=,"
|
|
|
|
|
"MD5=LJDK2+9ClF8Nz/K5WZd/+A==");
|
|
|
|
|
std::vector<Checksum> result;
|
|
|
|
|
httpResponse.getDigest(result);
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, result.size());
|
|
|
|
|