mirror of https://github.com/aria2/aria2
Refactor HttpConnection and its neighbor objects
parent
d485c8e767
commit
47402c5f29
|
@ -69,6 +69,12 @@ HttpRequestEntry::HttpRequestEntry
|
||||||
|
|
||||||
HttpRequestEntry::~HttpRequestEntry() {}
|
HttpRequestEntry::~HttpRequestEntry() {}
|
||||||
|
|
||||||
|
const std::unique_ptr<HttpHeaderProcessor>&
|
||||||
|
HttpRequestEntry::getHttpHeaderProcessor() const
|
||||||
|
{
|
||||||
|
return proc_;
|
||||||
|
}
|
||||||
|
|
||||||
HttpConnection::HttpConnection
|
HttpConnection::HttpConnection
|
||||||
(cuid_t cuid,
|
(cuid_t cuid,
|
||||||
const std::shared_ptr<SocketCore>& socket,
|
const std::shared_ptr<SocketCore>& socket,
|
||||||
|
@ -99,29 +105,28 @@ std::string HttpConnection::eraseConfidentialInfo(const std::string& request)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpConnection::sendRequest(const std::shared_ptr<HttpRequest>& httpRequest)
|
void HttpConnection::sendRequest
|
||||||
|
(const std::shared_ptr<HttpRequest>& httpRequest, std::string request)
|
||||||
{
|
{
|
||||||
std::string request = httpRequest->createRequest();
|
|
||||||
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
||||||
cuid_,
|
cuid_,
|
||||||
eraseConfidentialInfo(request).c_str()));
|
eraseConfidentialInfo(request).c_str()));
|
||||||
socketBuffer_.pushStr(std::move(request));
|
socketBuffer_.pushStr(std::move(request));
|
||||||
socketBuffer_.send();
|
socketBuffer_.send();
|
||||||
std::shared_ptr<HttpRequestEntry> entry(new HttpRequestEntry(httpRequest));
|
outstandingHttpRequests_.push_back(make_unique<HttpRequestEntry>
|
||||||
outstandingHttpRequests_.push_back(entry);
|
(httpRequest));
|
||||||
|
}
|
||||||
|
|
||||||
|
void HttpConnection::sendRequest
|
||||||
|
(const std::shared_ptr<HttpRequest>& httpRequest)
|
||||||
|
{
|
||||||
|
sendRequest(httpRequest, httpRequest->createRequest());
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpConnection::sendProxyRequest
|
void HttpConnection::sendProxyRequest
|
||||||
(const std::shared_ptr<HttpRequest>& httpRequest)
|
(const std::shared_ptr<HttpRequest>& httpRequest)
|
||||||
{
|
{
|
||||||
std::string request = httpRequest->createProxyRequest();
|
sendRequest(httpRequest, httpRequest->createProxyRequest());
|
||||||
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
|
|
||||||
cuid_,
|
|
||||||
eraseConfidentialInfo(request).c_str()));
|
|
||||||
socketBuffer_.pushStr(std::move(request));
|
|
||||||
socketBuffer_.send();
|
|
||||||
std::shared_ptr<HttpRequestEntry> entry(new HttpRequestEntry(httpRequest));
|
|
||||||
outstandingHttpRequests_.push_back(entry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<HttpResponse> HttpConnection::receiveResponse()
|
std::shared_ptr<HttpResponse> HttpConnection::receiveResponse()
|
||||||
|
@ -129,9 +134,6 @@ std::shared_ptr<HttpResponse> HttpConnection::receiveResponse()
|
||||||
if(outstandingHttpRequests_.empty()) {
|
if(outstandingHttpRequests_.empty()) {
|
||||||
throw DL_ABORT_EX(EX_NO_HTTP_REQUEST_ENTRY_FOUND);
|
throw DL_ABORT_EX(EX_NO_HTTP_REQUEST_ENTRY_FOUND);
|
||||||
}
|
}
|
||||||
std::shared_ptr<HttpRequestEntry> entry = outstandingHttpRequests_.front();
|
|
||||||
const std::shared_ptr<HttpHeaderProcessor>& proc =
|
|
||||||
entry->getHttpHeaderProcessor();
|
|
||||||
if(socketRecvBuffer_->bufferEmpty()) {
|
if(socketRecvBuffer_->bufferEmpty()) {
|
||||||
if(socketRecvBuffer_->recv() == 0 &&
|
if(socketRecvBuffer_->recv() == 0 &&
|
||||||
!socket_->wantRead() && !socket_->wantWrite()) {
|
!socket_->wantRead() && !socket_->wantWrite()) {
|
||||||
|
@ -139,16 +141,17 @@ std::shared_ptr<HttpResponse> HttpConnection::receiveResponse()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::shared_ptr<HttpResponse> httpResponse;
|
std::shared_ptr<HttpResponse> httpResponse;
|
||||||
|
const auto& proc = outstandingHttpRequests_.front()->getHttpHeaderProcessor();
|
||||||
if(proc->parse(socketRecvBuffer_->getBuffer(),
|
if(proc->parse(socketRecvBuffer_->getBuffer(),
|
||||||
socketRecvBuffer_->getBufferLength())) {
|
socketRecvBuffer_->getBufferLength())) {
|
||||||
const std::shared_ptr<HttpHeader>& httpHeader = proc->getResult();
|
|
||||||
A2_LOG_INFO(fmt(MSG_RECEIVE_RESPONSE,
|
A2_LOG_INFO(fmt(MSG_RECEIVE_RESPONSE,
|
||||||
cuid_,
|
cuid_,
|
||||||
proc->getHeaderString().c_str()));
|
proc->getHeaderString().c_str()));
|
||||||
httpResponse.reset(new HttpResponse());
|
httpResponse.reset(new HttpResponse());
|
||||||
httpResponse->setCuid(cuid_);
|
httpResponse->setCuid(cuid_);
|
||||||
httpResponse->setHttpHeader(httpHeader);
|
httpResponse->setHttpHeader(proc->getResult());
|
||||||
httpResponse->setHttpRequest(entry->getHttpRequest());
|
httpResponse->setHttpRequest(outstandingHttpRequests_.front()->
|
||||||
|
getHttpRequest());
|
||||||
outstandingHttpRequests_.pop_front();
|
outstandingHttpRequests_.pop_front();
|
||||||
}
|
}
|
||||||
socketRecvBuffer_->shiftBuffer(proc->getLastBytesProcessed());
|
socketRecvBuffer_->shiftBuffer(proc->getLastBytesProcessed());
|
||||||
|
@ -157,10 +160,8 @@ std::shared_ptr<HttpResponse> HttpConnection::receiveResponse()
|
||||||
|
|
||||||
bool HttpConnection::isIssued(const std::shared_ptr<Segment>& segment) const
|
bool HttpConnection::isIssued(const std::shared_ptr<Segment>& segment) const
|
||||||
{
|
{
|
||||||
for(HttpRequestEntries::const_iterator itr = outstandingHttpRequests_.begin(),
|
for(const auto& entry : outstandingHttpRequests_) {
|
||||||
eoi = outstandingHttpRequests_.end(); itr != eoi; ++itr) {
|
if(*entry->getHttpRequest()->getSegment() == *segment) {
|
||||||
std::shared_ptr<HttpRequest> httpRequest = (*itr)->getHttpRequest();
|
|
||||||
if(*httpRequest->getSegment() == *segment) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ class SocketRecvBuffer;
|
||||||
class HttpRequestEntry {
|
class HttpRequestEntry {
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<HttpRequest> httpRequest_;
|
std::shared_ptr<HttpRequest> httpRequest_;
|
||||||
std::shared_ptr<HttpHeaderProcessor> proc_;
|
std::unique_ptr<HttpHeaderProcessor> proc_;
|
||||||
public:
|
public:
|
||||||
HttpRequestEntry(const std::shared_ptr<HttpRequest>& httpRequest);
|
HttpRequestEntry(const std::shared_ptr<HttpRequest>& httpRequest);
|
||||||
|
|
||||||
|
@ -68,13 +68,10 @@ public:
|
||||||
return httpRequest_;
|
return httpRequest_;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::shared_ptr<HttpHeaderProcessor>& getHttpHeaderProcessor() const
|
const std::unique_ptr<HttpHeaderProcessor>& getHttpHeaderProcessor() const;
|
||||||
{
|
|
||||||
return proc_;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::deque<std::shared_ptr<HttpRequestEntry> > HttpRequestEntries;
|
typedef std::deque<std::unique_ptr<HttpRequestEntry>> HttpRequestEntries;
|
||||||
|
|
||||||
class HttpConnection {
|
class HttpConnection {
|
||||||
private:
|
private:
|
||||||
|
@ -86,6 +83,8 @@ private:
|
||||||
HttpRequestEntries outstandingHttpRequests_;
|
HttpRequestEntries outstandingHttpRequests_;
|
||||||
|
|
||||||
std::string eraseConfidentialInfo(const std::string& request);
|
std::string eraseConfidentialInfo(const std::string& request);
|
||||||
|
void sendRequest
|
||||||
|
(const std::shared_ptr<HttpRequest>& httpRequest, std::string request);
|
||||||
public:
|
public:
|
||||||
HttpConnection
|
HttpConnection
|
||||||
(cuid_t cuid,
|
(cuid_t cuid,
|
||||||
|
|
|
@ -391,9 +391,9 @@ void HttpHeaderProcessor::clear()
|
||||||
headers_.clear();
|
headers_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::shared_ptr<HttpHeader>& HttpHeaderProcessor::getResult() const
|
std::unique_ptr<HttpHeader> HttpHeaderProcessor::getResult()
|
||||||
{
|
{
|
||||||
return result_;
|
return std::move(result_);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string HttpHeaderProcessor::getHeaderString() const
|
std::string HttpHeaderProcessor::getHeaderString() const
|
||||||
|
|
|
@ -70,10 +70,11 @@ public:
|
||||||
size_t getLastBytesProcessed() const;
|
size_t getLastBytesProcessed() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes the received header as a http response header and returns
|
* Processes the received header as a http response header and
|
||||||
* HttpHeader object.
|
* returns HttpHeader object. This method transfers the ownership of
|
||||||
|
* resulting HttpHeader to the caller.
|
||||||
*/
|
*/
|
||||||
const std::shared_ptr<HttpHeader>& getResult() const;
|
std::unique_ptr<HttpHeader> getResult();
|
||||||
|
|
||||||
std::string getHeaderString() const;
|
std::string getHeaderString() const;
|
||||||
|
|
||||||
|
@ -88,7 +89,7 @@ private:
|
||||||
std::string buf_;
|
std::string buf_;
|
||||||
std::string lastFieldName_;
|
std::string lastFieldName_;
|
||||||
int lastFieldHdKey_;
|
int lastFieldHdKey_;
|
||||||
std::shared_ptr<HttpHeader> result_;
|
std::unique_ptr<HttpHeader> result_;
|
||||||
std::string headers_;
|
std::string headers_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -365,7 +365,7 @@ bool HttpRequest::authenticationUsed() const
|
||||||
return authConfig_.get();
|
return authConfig_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::shared_ptr<AuthConfig>& HttpRequest::getAuthConfig() const
|
const std::unique_ptr<AuthConfig>& HttpRequest::getAuthConfig() const
|
||||||
{
|
{
|
||||||
return authConfig_;
|
return authConfig_;
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ private:
|
||||||
|
|
||||||
const Option* option_;
|
const Option* option_;
|
||||||
|
|
||||||
std::shared_ptr<AuthConfig> authConfig_;
|
std::unique_ptr<AuthConfig> authConfig_;
|
||||||
|
|
||||||
std::shared_ptr<Request> proxyRequest_;
|
std::shared_ptr<Request> proxyRequest_;
|
||||||
|
|
||||||
|
@ -210,7 +210,7 @@ public:
|
||||||
|
|
||||||
// Returns AuthConfig used in the last invocation of
|
// Returns AuthConfig used in the last invocation of
|
||||||
// createRequest().
|
// createRequest().
|
||||||
const std::shared_ptr<AuthConfig>& getAuthConfig() const;
|
const std::unique_ptr<AuthConfig>& getAuthConfig() const;
|
||||||
|
|
||||||
void setFileEntry(const std::shared_ptr<FileEntry>& fileEntry);
|
void setFileEntry(const std::shared_ptr<FileEntry>& fileEntry);
|
||||||
|
|
||||||
|
|
|
@ -256,9 +256,14 @@ std::string HttpResponse::getContentType() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpResponse::setHttpHeader(const std::shared_ptr<HttpHeader>& httpHeader)
|
void HttpResponse::setHttpHeader(std::unique_ptr<HttpHeader> httpHeader)
|
||||||
{
|
{
|
||||||
httpHeader_ = httpHeader;
|
httpHeader_ = std::move(httpHeader);
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::unique_ptr<HttpHeader>& HttpResponse::getHttpHeader() const
|
||||||
|
{
|
||||||
|
return httpHeader_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpResponse::setHttpRequest(const std::shared_ptr<HttpRequest>& httpRequest)
|
void HttpResponse::setHttpRequest(const std::shared_ptr<HttpRequest>& httpRequest)
|
||||||
|
|
|
@ -57,7 +57,7 @@ class HttpResponse {
|
||||||
private:
|
private:
|
||||||
cuid_t cuid_;
|
cuid_t cuid_;
|
||||||
std::shared_ptr<HttpRequest> httpRequest_;
|
std::shared_ptr<HttpRequest> httpRequest_;
|
||||||
std::shared_ptr<HttpHeader> httpHeader_;
|
std::unique_ptr<HttpHeader> httpHeader_;
|
||||||
public:
|
public:
|
||||||
HttpResponse();
|
HttpResponse();
|
||||||
|
|
||||||
|
@ -103,12 +103,9 @@ public:
|
||||||
// Returns type "/" subtype. The parameter is removed.
|
// Returns type "/" subtype. The parameter is removed.
|
||||||
std::string getContentType() const;
|
std::string getContentType() const;
|
||||||
|
|
||||||
void setHttpHeader(const std::shared_ptr<HttpHeader>& httpHeader);
|
void setHttpHeader(std::unique_ptr<HttpHeader> httpHeader);
|
||||||
|
|
||||||
const std::shared_ptr<HttpHeader>& getHttpHeader() const
|
const std::unique_ptr<HttpHeader>& getHttpHeader() const;
|
||||||
{
|
|
||||||
return httpHeader_;
|
|
||||||
}
|
|
||||||
|
|
||||||
int getStatusCode() const;
|
int getStatusCode() const;
|
||||||
|
|
||||||
|
|
|
@ -165,7 +165,7 @@ bool HttpResponseCommand::executeInternal()
|
||||||
httpResponse->validateResponse();
|
httpResponse->validateResponse();
|
||||||
httpResponse->retrieveCookie();
|
httpResponse->retrieveCookie();
|
||||||
|
|
||||||
std::shared_ptr<HttpHeader> httpHeader = httpResponse->getHttpHeader();
|
const auto& httpHeader = httpResponse->getHttpHeader();
|
||||||
// Disable persistent connection if:
|
// Disable persistent connection if:
|
||||||
// Connection: close is received or the remote server is not HTTP/1.1.
|
// Connection: close is received or the remote server is not HTTP/1.1.
|
||||||
// We don't care whether non-HTTP/1.1 server returns Connection: keep-alive.
|
// We don't care whether non-HTTP/1.1 server returns Connection: keep-alive.
|
||||||
|
|
|
@ -76,7 +76,7 @@ void HttpHeaderProcessorTest::testParse3()
|
||||||
"Content-Type:\r\n"
|
"Content-Type:\r\n"
|
||||||
"\r\n";
|
"\r\n";
|
||||||
CPPUNIT_ASSERT(proc.parse(s));
|
CPPUNIT_ASSERT(proc.parse(s));
|
||||||
std::shared_ptr<HttpHeader> h = proc.getResult();
|
auto h = proc.getResult();
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("close"), h->find(HttpHeader::CONNECTION));
|
CPPUNIT_ASSERT_EQUAL(std::string("close"), h->find(HttpHeader::CONNECTION));
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("text1 text2 text3"),
|
CPPUNIT_ASSERT_EQUAL(std::string("text1 text2 text3"),
|
||||||
h->find(HttpHeader::ACCEPT_ENCODING));
|
h->find(HttpHeader::ACCEPT_ENCODING));
|
||||||
|
@ -136,7 +136,7 @@ void HttpHeaderProcessorTest::testGetHttpResponseHeader()
|
||||||
|
|
||||||
CPPUNIT_ASSERT(proc.parse(hd));
|
CPPUNIT_ASSERT(proc.parse(hd));
|
||||||
|
|
||||||
std::shared_ptr<HttpHeader> header = proc.getResult();
|
auto header = proc.getResult();
|
||||||
CPPUNIT_ASSERT_EQUAL(404, header->getStatusCode());
|
CPPUNIT_ASSERT_EQUAL(404, header->getStatusCode());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("Not Found"), header->getReasonPhrase());
|
CPPUNIT_ASSERT_EQUAL(std::string("Not Found"), header->getReasonPhrase());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("HTTP/1.1"), header->getVersion());
|
CPPUNIT_ASSERT_EQUAL(std::string("HTTP/1.1"), header->getVersion());
|
||||||
|
@ -153,7 +153,7 @@ void HttpHeaderProcessorTest::testGetHttpResponseHeader_statusOnly()
|
||||||
|
|
||||||
std::string hd = "HTTP/1.1 200\r\n\r\n";
|
std::string hd = "HTTP/1.1 200\r\n\r\n";
|
||||||
CPPUNIT_ASSERT(proc.parse(hd));
|
CPPUNIT_ASSERT(proc.parse(hd));
|
||||||
std::shared_ptr<HttpHeader> header = proc.getResult();
|
auto header = proc.getResult();
|
||||||
CPPUNIT_ASSERT_EQUAL(200, header->getStatusCode());
|
CPPUNIT_ASSERT_EQUAL(200, header->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,7 +269,7 @@ void HttpHeaderProcessorTest::testGetHttpRequestHeader()
|
||||||
|
|
||||||
CPPUNIT_ASSERT(proc.parse(request));
|
CPPUNIT_ASSERT(proc.parse(request));
|
||||||
|
|
||||||
std::shared_ptr<HttpHeader> httpHeader = proc.getResult();
|
auto httpHeader = proc.getResult();
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("GET"), httpHeader->getMethod());
|
CPPUNIT_ASSERT_EQUAL(std::string("GET"), httpHeader->getMethod());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("/index.html"),httpHeader->getRequestPath());
|
CPPUNIT_ASSERT_EQUAL(std::string("/index.html"),httpHeader->getRequestPath());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("HTTP/1.1"), httpHeader->getVersion());
|
CPPUNIT_ASSERT_EQUAL(std::string("HTTP/1.1"), httpHeader->getVersion());
|
||||||
|
|
|
@ -106,10 +106,10 @@ void HttpResponseTest::testGetContentLength_contentLength()
|
||||||
{
|
{
|
||||||
HttpResponse httpResponse;
|
HttpResponse httpResponse;
|
||||||
|
|
||||||
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
auto httpHeader = make_unique<HttpHeader>();
|
||||||
httpHeader->put(HttpHeader::CONTENT_LENGTH, "4294967296");
|
httpHeader->put(HttpHeader::CONTENT_LENGTH, "4294967296");
|
||||||
|
|
||||||
httpResponse.setHttpHeader(httpHeader);
|
httpResponse.setHttpHeader(std::move(httpHeader));
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL((int64_t)4294967296LL, httpResponse.getContentLength());
|
CPPUNIT_ASSERT_EQUAL((int64_t)4294967296LL, httpResponse.getContentLength());
|
||||||
}
|
}
|
||||||
|
@ -118,15 +118,14 @@ void HttpResponseTest::testGetEntityLength()
|
||||||
{
|
{
|
||||||
HttpResponse httpResponse;
|
HttpResponse httpResponse;
|
||||||
|
|
||||||
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
auto httpHeader = make_unique<HttpHeader>();
|
||||||
httpHeader->put(HttpHeader::CONTENT_LENGTH, "4294967296");
|
httpHeader->put(HttpHeader::CONTENT_LENGTH, "4294967296");
|
||||||
|
|
||||||
httpResponse.setHttpHeader(httpHeader);
|
httpResponse.setHttpHeader(std::move(httpHeader));
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL((int64_t)4294967296LL, httpResponse.getEntityLength());
|
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());
|
CPPUNIT_ASSERT_EQUAL((int64_t)4294967297LL, httpResponse.getEntityLength());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -134,10 +133,10 @@ void HttpResponseTest::testGetEntityLength()
|
||||||
void HttpResponseTest::testGetContentType()
|
void HttpResponseTest::testGetContentType()
|
||||||
{
|
{
|
||||||
HttpResponse httpResponse;
|
HttpResponse httpResponse;
|
||||||
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
auto httpHeader = make_unique<HttpHeader>();
|
||||||
httpHeader->put(HttpHeader::CONTENT_TYPE,
|
httpHeader->put(HttpHeader::CONTENT_TYPE,
|
||||||
"application/metalink+xml; charset=UTF-8");
|
"application/metalink+xml; charset=UTF-8");
|
||||||
httpResponse.setHttpHeader(httpHeader);
|
httpResponse.setHttpHeader(std::move(httpHeader));
|
||||||
// See paramter is ignored.
|
// See paramter is ignored.
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("application/metalink+xml"),
|
CPPUNIT_ASSERT_EQUAL(std::string("application/metalink+xml"),
|
||||||
httpResponse.getContentType());
|
httpResponse.getContentType());
|
||||||
|
@ -146,13 +145,12 @@ void HttpResponseTest::testGetContentType()
|
||||||
void HttpResponseTest::testDeterminFilename_without_ContentDisposition()
|
void HttpResponseTest::testDeterminFilename_without_ContentDisposition()
|
||||||
{
|
{
|
||||||
HttpResponse httpResponse;
|
HttpResponse httpResponse;
|
||||||
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
||||||
std::shared_ptr<HttpRequest> httpRequest(new HttpRequest());
|
std::shared_ptr<HttpRequest> httpRequest(new HttpRequest());
|
||||||
std::shared_ptr<Request> request(new Request());
|
std::shared_ptr<Request> request(new Request());
|
||||||
request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2");
|
request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2");
|
||||||
httpRequest->setRequest(request);
|
httpRequest->setRequest(request);
|
||||||
|
|
||||||
httpResponse.setHttpHeader(httpHeader);
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
||||||
httpResponse.setHttpRequest(httpRequest);
|
httpResponse.setHttpRequest(httpRequest);
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("aria2-1.0.0.tar.bz2"),
|
CPPUNIT_ASSERT_EQUAL(std::string("aria2-1.0.0.tar.bz2"),
|
||||||
|
@ -163,14 +161,14 @@ void HttpResponseTest::testDeterminFilename_with_ContentDisposition_zero_length
|
||||||
()
|
()
|
||||||
{
|
{
|
||||||
HttpResponse httpResponse;
|
HttpResponse httpResponse;
|
||||||
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
auto httpHeader = make_unique<HttpHeader>();
|
||||||
httpHeader->put(HttpHeader::CONTENT_DISPOSITION, "attachment; filename=\"\"");
|
httpHeader->put(HttpHeader::CONTENT_DISPOSITION, "attachment; filename=\"\"");
|
||||||
std::shared_ptr<HttpRequest> httpRequest(new HttpRequest());
|
std::shared_ptr<HttpRequest> httpRequest(new HttpRequest());
|
||||||
std::shared_ptr<Request> request(new Request());
|
std::shared_ptr<Request> request(new Request());
|
||||||
request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2");
|
request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2");
|
||||||
httpRequest->setRequest(request);
|
httpRequest->setRequest(request);
|
||||||
|
|
||||||
httpResponse.setHttpHeader(httpHeader);
|
httpResponse.setHttpHeader(std::move(httpHeader));
|
||||||
httpResponse.setHttpRequest(httpRequest);
|
httpResponse.setHttpRequest(httpRequest);
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("aria2-1.0.0.tar.bz2"),
|
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()
|
void HttpResponseTest::testDeterminFilename_with_ContentDisposition()
|
||||||
{
|
{
|
||||||
HttpResponse httpResponse;
|
HttpResponse httpResponse;
|
||||||
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
auto httpHeader = make_unique<HttpHeader>();
|
||||||
httpHeader->put(HttpHeader::CONTENT_DISPOSITION,
|
httpHeader->put(HttpHeader::CONTENT_DISPOSITION,
|
||||||
"attachment; filename=\"aria2-current.tar.bz2\"");
|
"attachment; filename=\"aria2-current.tar.bz2\"");
|
||||||
std::shared_ptr<HttpRequest> httpRequest(new HttpRequest());
|
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");
|
request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2");
|
||||||
httpRequest->setRequest(request);
|
httpRequest->setRequest(request);
|
||||||
|
|
||||||
httpResponse.setHttpHeader(httpHeader);
|
httpResponse.setHttpHeader(std::move(httpHeader));
|
||||||
httpResponse.setHttpRequest(httpRequest);
|
httpResponse.setHttpRequest(httpRequest);
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("aria2-current.tar.bz2"),
|
CPPUNIT_ASSERT_EQUAL(std::string("aria2-current.tar.bz2"),
|
||||||
|
@ -198,9 +196,8 @@ void HttpResponseTest::testDeterminFilename_with_ContentDisposition()
|
||||||
void HttpResponseTest::testGetRedirectURI_without_Location()
|
void HttpResponseTest::testGetRedirectURI_without_Location()
|
||||||
{
|
{
|
||||||
HttpResponse httpResponse;
|
HttpResponse httpResponse;
|
||||||
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
||||||
|
|
||||||
httpResponse.setHttpHeader(httpHeader);
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string(""),
|
CPPUNIT_ASSERT_EQUAL(std::string(""),
|
||||||
httpResponse.getRedirectURI());
|
httpResponse.getRedirectURI());
|
||||||
|
@ -209,9 +206,10 @@ void HttpResponseTest::testGetRedirectURI_without_Location()
|
||||||
void HttpResponseTest::testGetRedirectURI_with_Location()
|
void HttpResponseTest::testGetRedirectURI_with_Location()
|
||||||
{
|
{
|
||||||
HttpResponse httpResponse;
|
HttpResponse httpResponse;
|
||||||
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
auto httpHeader = make_unique<HttpHeader>();
|
||||||
httpHeader->put(HttpHeader::LOCATION, "http://localhost/download/aria2-1.0.0.tar.bz2");
|
httpHeader->put(HttpHeader::LOCATION,
|
||||||
httpResponse.setHttpHeader(httpHeader);
|
"http://localhost/download/aria2-1.0.0.tar.bz2");
|
||||||
|
httpResponse.setHttpHeader(std::move(httpHeader));
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL
|
CPPUNIT_ASSERT_EQUAL
|
||||||
(std::string("http://localhost/download/aria2-1.0.0.tar.bz2"),
|
(std::string("http://localhost/download/aria2-1.0.0.tar.bz2"),
|
||||||
|
@ -221,45 +219,37 @@ void HttpResponseTest::testGetRedirectURI_with_Location()
|
||||||
void HttpResponseTest::testIsRedirect()
|
void HttpResponseTest::testIsRedirect()
|
||||||
{
|
{
|
||||||
HttpResponse httpResponse;
|
HttpResponse httpResponse;
|
||||||
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
auto httpHeader = make_unique<HttpHeader>();
|
||||||
httpHeader->setStatusCode(200);
|
httpHeader->setStatusCode(200);
|
||||||
httpHeader->put(HttpHeader::LOCATION,
|
httpHeader->put(HttpHeader::LOCATION,
|
||||||
"http://localhost/download/aria2-1.0.0.tar.bz2");
|
"http://localhost/download/aria2-1.0.0.tar.bz2");
|
||||||
|
|
||||||
httpResponse.setHttpHeader(httpHeader);
|
httpResponse.setHttpHeader(std::move(httpHeader));
|
||||||
|
|
||||||
CPPUNIT_ASSERT(!httpResponse.isRedirect());
|
CPPUNIT_ASSERT(!httpResponse.isRedirect());
|
||||||
|
|
||||||
httpHeader->setStatusCode(301);
|
httpResponse.getHttpHeader()->setStatusCode(301);
|
||||||
|
|
||||||
CPPUNIT_ASSERT(httpResponse.isRedirect());
|
CPPUNIT_ASSERT(httpResponse.isRedirect());
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpResponseTest::testIsTransferEncodingSpecified()
|
void HttpResponseTest::testIsTransferEncodingSpecified()
|
||||||
{
|
{
|
||||||
HttpResponse httpResponse;
|
HttpResponse httpResponse;
|
||||||
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
||||||
|
|
||||||
httpResponse.setHttpHeader(httpHeader);
|
|
||||||
|
|
||||||
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
||||||
CPPUNIT_ASSERT(!httpResponse.isTransferEncodingSpecified());
|
CPPUNIT_ASSERT(!httpResponse.isTransferEncodingSpecified());
|
||||||
|
|
||||||
httpHeader->put(HttpHeader::TRANSFER_ENCODING, "chunked");
|
httpResponse.getHttpHeader()->put(HttpHeader::TRANSFER_ENCODING, "chunked");
|
||||||
|
|
||||||
CPPUNIT_ASSERT(httpResponse.isTransferEncodingSpecified());
|
CPPUNIT_ASSERT(httpResponse.isTransferEncodingSpecified());
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpResponseTest::testGetTransferEncoding()
|
void HttpResponseTest::testGetTransferEncoding()
|
||||||
{
|
{
|
||||||
HttpResponse httpResponse;
|
HttpResponse httpResponse;
|
||||||
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
||||||
|
|
||||||
httpResponse.setHttpHeader(httpHeader);
|
|
||||||
|
|
||||||
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string(""), httpResponse.getTransferEncoding());
|
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"),
|
CPPUNIT_ASSERT_EQUAL(std::string("chunked"),
|
||||||
httpResponse.getTransferEncoding());
|
httpResponse.getTransferEncoding());
|
||||||
}
|
}
|
||||||
|
@ -267,56 +257,45 @@ void HttpResponseTest::testGetTransferEncoding()
|
||||||
void HttpResponseTest::testGetTransferEncodingStreamFilter()
|
void HttpResponseTest::testGetTransferEncodingStreamFilter()
|
||||||
{
|
{
|
||||||
HttpResponse httpResponse;
|
HttpResponse httpResponse;
|
||||||
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
||||||
|
|
||||||
httpResponse.setHttpHeader(httpHeader);
|
|
||||||
|
|
||||||
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
||||||
CPPUNIT_ASSERT(!httpResponse.getTransferEncodingStreamFilter());
|
CPPUNIT_ASSERT(!httpResponse.getTransferEncodingStreamFilter());
|
||||||
|
|
||||||
httpHeader->put(HttpHeader::TRANSFER_ENCODING, "chunked");
|
httpResponse.getHttpHeader()->put(HttpHeader::TRANSFER_ENCODING, "chunked");
|
||||||
|
|
||||||
CPPUNIT_ASSERT(httpResponse.getTransferEncodingStreamFilter());
|
CPPUNIT_ASSERT(httpResponse.getTransferEncodingStreamFilter());
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpResponseTest::testIsContentEncodingSpecified()
|
void HttpResponseTest::testIsContentEncodingSpecified()
|
||||||
{
|
{
|
||||||
HttpResponse httpResponse;
|
HttpResponse httpResponse;
|
||||||
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
||||||
|
|
||||||
httpResponse.setHttpHeader(httpHeader);
|
|
||||||
|
|
||||||
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
||||||
CPPUNIT_ASSERT(!httpResponse.isContentEncodingSpecified());
|
CPPUNIT_ASSERT(!httpResponse.isContentEncodingSpecified());
|
||||||
|
|
||||||
httpHeader->put(HttpHeader::CONTENT_ENCODING, "gzip");
|
httpResponse.getHttpHeader()->put(HttpHeader::CONTENT_ENCODING, "gzip");
|
||||||
|
|
||||||
CPPUNIT_ASSERT(httpResponse.isContentEncodingSpecified());
|
CPPUNIT_ASSERT(httpResponse.isContentEncodingSpecified());
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpResponseTest::testGetContentEncoding()
|
void HttpResponseTest::testGetContentEncoding()
|
||||||
{
|
{
|
||||||
HttpResponse httpResponse;
|
HttpResponse httpResponse;
|
||||||
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
||||||
|
|
||||||
httpResponse.setHttpHeader(httpHeader);
|
|
||||||
|
|
||||||
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
||||||
CPPUNIT_ASSERT_EQUAL(A2STR::NIL, httpResponse.getContentEncoding());
|
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());
|
CPPUNIT_ASSERT_EQUAL(std::string("gzip"), httpResponse.getContentEncoding());
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpResponseTest::testGetContentEncodingStreamFilter()
|
void HttpResponseTest::testGetContentEncodingStreamFilter()
|
||||||
{
|
{
|
||||||
HttpResponse httpResponse;
|
HttpResponse httpResponse;
|
||||||
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
|
||||||
|
|
||||||
httpResponse.setHttpHeader(httpHeader);
|
|
||||||
|
|
||||||
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
||||||
CPPUNIT_ASSERT(!httpResponse.getContentEncodingStreamFilter());
|
CPPUNIT_ASSERT(!httpResponse.getContentEncodingStreamFilter());
|
||||||
|
|
||||||
#ifdef HAVE_ZLIB
|
#ifdef HAVE_ZLIB
|
||||||
httpHeader->put(HttpHeader::CONTENT_ENCODING, "gzip");
|
httpResponse.getHttpHeader()->put(HttpHeader::CONTENT_ENCODING, "gzip");
|
||||||
{
|
{
|
||||||
std::shared_ptr<StreamFilter> filter =
|
std::shared_ptr<StreamFilter> filter =
|
||||||
httpResponse.getContentEncodingStreamFilter();
|
httpResponse.getContentEncodingStreamFilter();
|
||||||
|
@ -324,9 +303,8 @@ void HttpResponseTest::testGetContentEncodingStreamFilter()
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("GZipDecodingStreamFilter"),
|
CPPUNIT_ASSERT_EQUAL(std::string("GZipDecodingStreamFilter"),
|
||||||
filter->getName());
|
filter->getName());
|
||||||
}
|
}
|
||||||
httpHeader.reset(new HttpHeader());
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
||||||
httpResponse.setHttpHeader(httpHeader);
|
httpResponse.getHttpHeader()->put(HttpHeader::CONTENT_ENCODING, "deflate");
|
||||||
httpHeader->put(HttpHeader::CONTENT_ENCODING, "deflate");
|
|
||||||
{
|
{
|
||||||
std::shared_ptr<StreamFilter> filter =
|
std::shared_ptr<StreamFilter> filter =
|
||||||
httpResponse.getContentEncodingStreamFilter();
|
httpResponse.getContentEncodingStreamFilter();
|
||||||
|
@ -335,9 +313,8 @@ void HttpResponseTest::testGetContentEncodingStreamFilter()
|
||||||
filter->getName());
|
filter->getName());
|
||||||
}
|
}
|
||||||
#endif // HAVE_ZLIB
|
#endif // HAVE_ZLIB
|
||||||
httpHeader.reset(new HttpHeader());
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
||||||
httpResponse.setHttpHeader(httpHeader);
|
httpResponse.getHttpHeader()->put(HttpHeader::CONTENT_ENCODING, "bzip2");
|
||||||
httpHeader->put(HttpHeader::CONTENT_ENCODING, "bzip2");
|
|
||||||
{
|
{
|
||||||
std::shared_ptr<StreamFilter> filter =
|
std::shared_ptr<StreamFilter> filter =
|
||||||
httpResponse.getContentEncodingStreamFilter();
|
httpResponse.getContentEncodingStreamFilter();
|
||||||
|
@ -348,10 +325,8 @@ void HttpResponseTest::testGetContentEncodingStreamFilter()
|
||||||
void HttpResponseTest::testValidateResponse()
|
void HttpResponseTest::testValidateResponse()
|
||||||
{
|
{
|
||||||
HttpResponse httpResponse;
|
HttpResponse httpResponse;
|
||||||
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
||||||
httpResponse.setHttpHeader(httpHeader);
|
httpResponse.getHttpHeader()->setStatusCode(301);
|
||||||
|
|
||||||
httpHeader->setStatusCode(301);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
httpResponse.validateResponse();
|
httpResponse.validateResponse();
|
||||||
|
@ -359,7 +334,8 @@ void HttpResponseTest::testValidateResponse()
|
||||||
} catch(Exception& e) {
|
} catch(Exception& e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
httpHeader->put(HttpHeader::LOCATION,
|
httpResponse.getHttpHeader()->put
|
||||||
|
(HttpHeader::LOCATION,
|
||||||
"http://localhost/archives/aria2-1.0.0.tar.bz2");
|
"http://localhost/archives/aria2-1.0.0.tar.bz2");
|
||||||
try {
|
try {
|
||||||
httpResponse.validateResponse();
|
httpResponse.validateResponse();
|
||||||
|
@ -371,8 +347,8 @@ void HttpResponseTest::testValidateResponse()
|
||||||
void HttpResponseTest::testValidateResponse_good_range()
|
void HttpResponseTest::testValidateResponse_good_range()
|
||||||
{
|
{
|
||||||
HttpResponse httpResponse;
|
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<HttpRequest> httpRequest(new HttpRequest());
|
||||||
std::shared_ptr<Piece> p(new Piece(1, 1024*1024));
|
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");
|
request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2");
|
||||||
httpRequest->setRequest(request);
|
httpRequest->setRequest(request);
|
||||||
httpResponse.setHttpRequest(httpRequest);
|
httpResponse.setHttpRequest(httpRequest);
|
||||||
httpHeader->setStatusCode(206);
|
httpResponse.getHttpHeader()->setStatusCode(206);
|
||||||
httpHeader->put(HttpHeader::CONTENT_RANGE, "bytes 1048576-10485760/10485760");
|
httpResponse.getHttpHeader()->put(HttpHeader::CONTENT_RANGE,
|
||||||
|
"bytes 1048576-10485760/10485760");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
httpResponse.validateResponse();
|
httpResponse.validateResponse();
|
||||||
|
@ -398,8 +375,8 @@ void HttpResponseTest::testValidateResponse_good_range()
|
||||||
void HttpResponseTest::testValidateResponse_bad_range()
|
void HttpResponseTest::testValidateResponse_bad_range()
|
||||||
{
|
{
|
||||||
HttpResponse httpResponse;
|
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<HttpRequest> httpRequest(new HttpRequest());
|
||||||
std::shared_ptr<Piece> p(new Piece(1, 1024*1024));
|
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");
|
request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2");
|
||||||
httpRequest->setRequest(request);
|
httpRequest->setRequest(request);
|
||||||
httpResponse.setHttpRequest(httpRequest);
|
httpResponse.setHttpRequest(httpRequest);
|
||||||
httpHeader->setStatusCode(206);
|
httpResponse.getHttpHeader()->setStatusCode(206);
|
||||||
httpHeader->put(HttpHeader::CONTENT_RANGE, "bytes 0-10485760/10485761");
|
httpResponse.getHttpHeader()->put(HttpHeader::CONTENT_RANGE,
|
||||||
|
"bytes 0-10485760/10485761");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
httpResponse.validateResponse();
|
httpResponse.validateResponse();
|
||||||
|
@ -424,8 +402,7 @@ void HttpResponseTest::testValidateResponse_bad_range()
|
||||||
void HttpResponseTest::testValidateResponse_chunked()
|
void HttpResponseTest::testValidateResponse_chunked()
|
||||||
{
|
{
|
||||||
HttpResponse httpResponse;
|
HttpResponse httpResponse;
|
||||||
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
||||||
httpResponse.setHttpHeader(httpHeader);
|
|
||||||
|
|
||||||
std::shared_ptr<HttpRequest> httpRequest(new HttpRequest());
|
std::shared_ptr<HttpRequest> httpRequest(new HttpRequest());
|
||||||
std::shared_ptr<Piece> p(new Piece(1, 1024*1024));
|
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");
|
request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2");
|
||||||
httpRequest->setRequest(request);
|
httpRequest->setRequest(request);
|
||||||
httpResponse.setHttpRequest(httpRequest);
|
httpResponse.setHttpRequest(httpRequest);
|
||||||
httpHeader->setStatusCode(206);
|
httpResponse.getHttpHeader()->setStatusCode(206);
|
||||||
httpHeader->put(HttpHeader::CONTENT_RANGE, "bytes 0-10485760/10485761");
|
httpResponse.getHttpHeader()->put(HttpHeader::CONTENT_RANGE,
|
||||||
httpHeader->put(HttpHeader::TRANSFER_ENCODING, "chunked");
|
"bytes 0-10485760/10485761");
|
||||||
|
httpResponse.getHttpHeader()->put(HttpHeader::TRANSFER_ENCODING, "chunked");
|
||||||
|
|
||||||
// if transfer-encoding is specified, then range validation is skipped.
|
// if transfer-encoding is specified, then range validation is skipped.
|
||||||
try {
|
try {
|
||||||
|
@ -452,9 +430,8 @@ void HttpResponseTest::testValidateResponse_chunked()
|
||||||
void HttpResponseTest::testValidateResponse_withIfModifiedSince()
|
void HttpResponseTest::testValidateResponse_withIfModifiedSince()
|
||||||
{
|
{
|
||||||
HttpResponse httpResponse;
|
HttpResponse httpResponse;
|
||||||
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
||||||
httpResponse.setHttpHeader(httpHeader);
|
httpResponse.getHttpHeader()->setStatusCode(304);
|
||||||
httpHeader->setStatusCode(304);
|
|
||||||
std::shared_ptr<HttpRequest> httpRequest(new HttpRequest());
|
std::shared_ptr<HttpRequest> httpRequest(new HttpRequest());
|
||||||
httpResponse.setHttpRequest(httpRequest);
|
httpResponse.setHttpRequest(httpRequest);
|
||||||
try {
|
try {
|
||||||
|
@ -469,8 +446,8 @@ void HttpResponseTest::testValidateResponse_withIfModifiedSince()
|
||||||
void HttpResponseTest::testProcessRedirect()
|
void HttpResponseTest::testProcessRedirect()
|
||||||
{
|
{
|
||||||
HttpResponse httpResponse;
|
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<HttpRequest> httpRequest(new HttpRequest());
|
||||||
std::shared_ptr<Request> request(new Request());
|
std::shared_ptr<Request> request(new Request());
|
||||||
|
@ -478,22 +455,24 @@ void HttpResponseTest::testProcessRedirect()
|
||||||
httpRequest->setRequest(request);
|
httpRequest->setRequest(request);
|
||||||
httpResponse.setHttpRequest(httpRequest);
|
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();
|
httpResponse.processRedirect();
|
||||||
|
|
||||||
httpHeader->clearField();
|
httpResponse.getHttpHeader()->clearField();
|
||||||
|
|
||||||
// Test for percent-encode
|
// 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();
|
httpResponse.processRedirect();
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("http://example.org/white%20space"),
|
CPPUNIT_ASSERT_EQUAL(std::string("http://example.org/white%20space"),
|
||||||
request->getCurrentUri());
|
request->getCurrentUri());
|
||||||
|
|
||||||
httpHeader->clearField();
|
httpResponse.getHttpHeader()->clearField();
|
||||||
|
|
||||||
// Give unsupported scheme
|
// Give unsupported scheme
|
||||||
httpHeader->put(HttpHeader::LOCATION,
|
httpResponse.getHttpHeader()->put
|
||||||
"unsupported://mirror/aria2-1.0.0.tar.bz2");
|
(HttpHeader::LOCATION, "unsupported://mirror/aria2-1.0.0.tar.bz2");
|
||||||
try {
|
try {
|
||||||
httpResponse.processRedirect();
|
httpResponse.processRedirect();
|
||||||
CPPUNIT_FAIL("DlRetryEx exception must be thrown.");
|
CPPUNIT_FAIL("DlRetryEx exception must be thrown.");
|
||||||
|
@ -507,8 +486,8 @@ void HttpResponseTest::testProcessRedirect()
|
||||||
void HttpResponseTest::testRetrieveCookie()
|
void HttpResponseTest::testRetrieveCookie()
|
||||||
{
|
{
|
||||||
HttpResponse httpResponse;
|
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<HttpRequest> httpRequest(new HttpRequest());
|
||||||
std::shared_ptr<Request> request(new Request());
|
std::shared_ptr<Request> request(new Request());
|
||||||
|
@ -518,13 +497,15 @@ void HttpResponseTest::testRetrieveCookie()
|
||||||
httpRequest->setCookieStorage(&st);
|
httpRequest->setCookieStorage(&st);
|
||||||
httpResponse.setHttpRequest(httpRequest);
|
httpResponse.setHttpRequest(httpRequest);
|
||||||
|
|
||||||
httpHeader->put(HttpHeader::SET_COOKIE,
|
httpResponse.getHttpHeader()->put
|
||||||
|
(HttpHeader::SET_COOKIE,
|
||||||
"k1=v1; expires=Sun, 10-Jun-2007 11:00:00 GMT;"
|
"k1=v1; expires=Sun, 10-Jun-2007 11:00:00 GMT;"
|
||||||
"path=/; domain=.aria2.org;");
|
"path=/; domain=.aria2.org;");
|
||||||
httpHeader->put(HttpHeader::SET_COOKIE,
|
httpResponse.getHttpHeader()->put
|
||||||
|
(HttpHeader::SET_COOKIE,
|
||||||
"k2=v2; expires=Sun, 01-Jan-38 00:00:00 GMT;"
|
"k2=v2; expires=Sun, 01-Jan-38 00:00:00 GMT;"
|
||||||
"path=/; domain=.aria2.org;");
|
"path=/; domain=.aria2.org;");
|
||||||
httpHeader->put(HttpHeader::SET_COOKIE, "k3=v3;");
|
httpResponse.getHttpHeader()->put(HttpHeader::SET_COOKIE, "k3=v3;");
|
||||||
|
|
||||||
httpResponse.retrieveCookie();
|
httpResponse.retrieveCookie();
|
||||||
|
|
||||||
|
@ -539,69 +520,78 @@ void HttpResponseTest::testRetrieveCookie()
|
||||||
void HttpResponseTest::testSupportsPersistentConnection()
|
void HttpResponseTest::testSupportsPersistentConnection()
|
||||||
{
|
{
|
||||||
HttpResponse httpResponse;
|
HttpResponse httpResponse;
|
||||||
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
||||||
httpResponse.setHttpHeader(httpHeader);
|
|
||||||
std::shared_ptr<HttpRequest> httpRequest(new HttpRequest());
|
std::shared_ptr<HttpRequest> httpRequest(new HttpRequest());
|
||||||
httpResponse.setHttpRequest(httpRequest);
|
httpResponse.setHttpRequest(httpRequest);
|
||||||
|
|
||||||
httpHeader->setVersion("HTTP/1.1");
|
httpResponse.getHttpHeader()->setVersion("HTTP/1.1");
|
||||||
CPPUNIT_ASSERT(httpResponse.supportsPersistentConnection());
|
CPPUNIT_ASSERT(httpResponse.supportsPersistentConnection());
|
||||||
httpHeader->put(HttpHeader::CONNECTION, "close");
|
httpResponse.getHttpHeader()->put(HttpHeader::CONNECTION, "close");
|
||||||
CPPUNIT_ASSERT(!httpResponse.supportsPersistentConnection());
|
CPPUNIT_ASSERT(!httpResponse.supportsPersistentConnection());
|
||||||
httpHeader->clearField();
|
httpResponse.getHttpHeader()->clearField();
|
||||||
httpHeader->put(HttpHeader::CONNECTION, "keep-alive");
|
httpResponse.getHttpHeader()->put(HttpHeader::CONNECTION, "keep-alive");
|
||||||
CPPUNIT_ASSERT(httpResponse.supportsPersistentConnection());
|
CPPUNIT_ASSERT(httpResponse.supportsPersistentConnection());
|
||||||
httpHeader->clearField();
|
httpResponse.getHttpHeader()->clearField();
|
||||||
|
|
||||||
httpHeader->setVersion("HTTP/1.0");
|
httpResponse.getHttpHeader()->setVersion("HTTP/1.0");
|
||||||
CPPUNIT_ASSERT(!httpResponse.supportsPersistentConnection());
|
CPPUNIT_ASSERT(!httpResponse.supportsPersistentConnection());
|
||||||
httpHeader->put(HttpHeader::CONNECTION, "close");
|
httpResponse.getHttpHeader()->put(HttpHeader::CONNECTION, "close");
|
||||||
CPPUNIT_ASSERT(!httpResponse.supportsPersistentConnection());
|
CPPUNIT_ASSERT(!httpResponse.supportsPersistentConnection());
|
||||||
httpHeader->clearField();
|
httpResponse.getHttpHeader()->clearField();
|
||||||
httpHeader->put(HttpHeader::CONNECTION, "keep-alive");
|
httpResponse.getHttpHeader()->put(HttpHeader::CONNECTION, "keep-alive");
|
||||||
CPPUNIT_ASSERT(httpResponse.supportsPersistentConnection());
|
CPPUNIT_ASSERT(httpResponse.supportsPersistentConnection());
|
||||||
httpHeader->clearField();
|
httpResponse.getHttpHeader()->clearField();
|
||||||
|
|
||||||
// test proxy connection
|
// test proxy connection
|
||||||
std::shared_ptr<Request> proxyRequest(new Request());
|
std::shared_ptr<Request> proxyRequest(new Request());
|
||||||
httpRequest->setProxyRequest(proxyRequest);
|
httpRequest->setProxyRequest(proxyRequest);
|
||||||
|
|
||||||
httpHeader->setVersion("HTTP/1.1");
|
httpResponse.getHttpHeader()->setVersion("HTTP/1.1");
|
||||||
CPPUNIT_ASSERT(httpResponse.supportsPersistentConnection());
|
CPPUNIT_ASSERT(httpResponse.supportsPersistentConnection());
|
||||||
httpHeader->put(HttpHeader::CONNECTION, "close");
|
httpResponse.getHttpHeader()->put(HttpHeader::CONNECTION, "close");
|
||||||
CPPUNIT_ASSERT(!httpResponse.supportsPersistentConnection());
|
CPPUNIT_ASSERT(!httpResponse.supportsPersistentConnection());
|
||||||
httpHeader->clearField();
|
httpResponse.getHttpHeader()->clearField();
|
||||||
httpHeader->put(HttpHeader::CONNECTION, "keep-alive");
|
httpResponse.getHttpHeader()->put(HttpHeader::CONNECTION, "keep-alive");
|
||||||
CPPUNIT_ASSERT(httpResponse.supportsPersistentConnection());
|
CPPUNIT_ASSERT(httpResponse.supportsPersistentConnection());
|
||||||
httpHeader->clearField();
|
httpResponse.getHttpHeader()->clearField();
|
||||||
|
|
||||||
httpHeader->setVersion("HTTP/1.0");
|
httpResponse.getHttpHeader()->setVersion("HTTP/1.0");
|
||||||
CPPUNIT_ASSERT(!httpResponse.supportsPersistentConnection());
|
CPPUNIT_ASSERT(!httpResponse.supportsPersistentConnection());
|
||||||
httpHeader->put(HttpHeader::CONNECTION, "close");
|
httpResponse.getHttpHeader()->put(HttpHeader::CONNECTION, "close");
|
||||||
CPPUNIT_ASSERT(!httpResponse.supportsPersistentConnection());
|
CPPUNIT_ASSERT(!httpResponse.supportsPersistentConnection());
|
||||||
httpHeader->clearField();
|
httpResponse.getHttpHeader()->clearField();
|
||||||
httpHeader->put(HttpHeader::CONNECTION, "keep-alive");
|
httpResponse.getHttpHeader()->put(HttpHeader::CONNECTION, "keep-alive");
|
||||||
CPPUNIT_ASSERT(httpResponse.supportsPersistentConnection());
|
CPPUNIT_ASSERT(httpResponse.supportsPersistentConnection());
|
||||||
httpHeader->clearField();
|
httpResponse.getHttpHeader()->clearField();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpResponseTest::testGetMetalinKHttpEntries()
|
void HttpResponseTest::testGetMetalinKHttpEntries()
|
||||||
{
|
{
|
||||||
HttpResponse httpResponse;
|
HttpResponse httpResponse;
|
||||||
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
||||||
httpResponse.setHttpHeader(httpHeader);
|
|
||||||
std::shared_ptr<Option> option(new Option());
|
std::shared_ptr<Option> option(new Option());
|
||||||
|
|
||||||
httpHeader->put(HttpHeader::LINK,
|
httpResponse.getHttpHeader()->put
|
||||||
|
(HttpHeader::LINK,
|
||||||
"<http://uri1/>; rel=duplicate; pri=1; pref; geo=JP");
|
"<http://uri1/>; rel=duplicate; pri=1; pref; geo=JP");
|
||||||
httpHeader->put(HttpHeader::LINK,
|
httpResponse.getHttpHeader()->put
|
||||||
|
(HttpHeader::LINK,
|
||||||
"<http://uri2/>; rel=duplicate");
|
"<http://uri2/>; rel=duplicate");
|
||||||
httpHeader->put(HttpHeader::LINK,
|
httpResponse.getHttpHeader()->put
|
||||||
|
(HttpHeader::LINK,
|
||||||
"<http://uri3/>;;;;;;;;rel=duplicate;;;;;pri=2;;;;;");
|
"<http://uri3/>;;;;;;;;rel=duplicate;;;;;pri=2;;;;;");
|
||||||
httpHeader->put(HttpHeader::LINK, "<http://uri4/>;rel=duplicate;=pri=1;pref");
|
httpResponse.getHttpHeader()->put
|
||||||
httpHeader->put(HttpHeader::LINK, "<http://describedby>; rel=describedby");
|
(HttpHeader::LINK,
|
||||||
httpHeader->put(HttpHeader::LINK, "<http://norel/>");
|
"<http://uri4/>;rel=duplicate;=pri=1;pref");
|
||||||
httpHeader->put(HttpHeader::LINK, "<baduri>; rel=duplicate; pri=-1;");
|
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;
|
std::vector<MetalinkHttpEntry> result;
|
||||||
httpResponse.getMetalinKHttpEntries(result, option);
|
httpResponse.getMetalinKHttpEntries(result, option);
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)5, result.size());
|
CPPUNIT_ASSERT_EQUAL((size_t)5, result.size());
|
||||||
|
@ -641,18 +631,21 @@ void HttpResponseTest::testGetMetalinKHttpEntries()
|
||||||
void HttpResponseTest::testGetDigest()
|
void HttpResponseTest::testGetDigest()
|
||||||
{
|
{
|
||||||
HttpResponse httpResponse;
|
HttpResponse httpResponse;
|
||||||
std::shared_ptr<HttpHeader> httpHeader(new HttpHeader());
|
httpResponse.setHttpHeader(make_unique<HttpHeader>());
|
||||||
httpResponse.setHttpHeader(httpHeader);
|
|
||||||
std::shared_ptr<Option> option(new Option());
|
std::shared_ptr<Option> option(new Option());
|
||||||
// Python binascii.hexlify(base64.b64decode(B64ED_HASH)) is handy to
|
// Python binascii.hexlify(base64.b64decode(B64ED_HASH)) is handy to
|
||||||
// retrieve ascii hex hash string.
|
// retrieve ascii hex hash string.
|
||||||
httpHeader->put(HttpHeader::DIGEST, "SHA-1=82AD8itGL/oYQ5BTPFANiYnp9oE=");
|
httpResponse.getHttpHeader()->put(HttpHeader::DIGEST,
|
||||||
httpHeader->put(HttpHeader::DIGEST, "NOT_SUPPORTED");
|
"SHA-1=82AD8itGL/oYQ5BTPFANiYnp9oE=");
|
||||||
httpHeader->put(HttpHeader::DIGEST,
|
httpResponse.getHttpHeader()->put(HttpHeader::DIGEST, "NOT_SUPPORTED");
|
||||||
|
httpResponse.getHttpHeader()->put
|
||||||
|
(HttpHeader::DIGEST,
|
||||||
"SHA-224=rQdowoLHQJTMVZ3rF7vmYOIzUXlu7F+FcMbPnA==");
|
"SHA-224=rQdowoLHQJTMVZ3rF7vmYOIzUXlu7F+FcMbPnA==");
|
||||||
httpHeader->put(HttpHeader::DIGEST,
|
httpResponse.getHttpHeader()->put
|
||||||
|
(HttpHeader::DIGEST,
|
||||||
"SHA-224=6Ik6LNZ1iPy6cbmlKO4NHfvxzaiurmHilMyhGA==");
|
"SHA-224=6Ik6LNZ1iPy6cbmlKO4NHfvxzaiurmHilMyhGA==");
|
||||||
httpHeader->put(HttpHeader::DIGEST,
|
httpResponse.getHttpHeader()->put
|
||||||
|
(HttpHeader::DIGEST,
|
||||||
"SHA-256=+D8nGudz3G/kpkVKQeDrI3xD57v0UeQmzGCZOk03nsU=,"
|
"SHA-256=+D8nGudz3G/kpkVKQeDrI3xD57v0UeQmzGCZOk03nsU=,"
|
||||||
"MD5=LJDK2+9ClF8Nz/K5WZd/+A==");
|
"MD5=LJDK2+9ClF8Nz/K5WZd/+A==");
|
||||||
std::vector<Checksum> result;
|
std::vector<Checksum> result;
|
||||||
|
|
Loading…
Reference in New Issue