short circuit asset request for invalid hash

This commit is contained in:
Stephen Birarda 2016-03-10 10:42:45 -08:00
parent 9d19bf85b1
commit 2bbeac6597
3 changed files with 13 additions and 9 deletions

View file

@ -35,6 +35,15 @@ void AssetRequest::start() {
qCWarning(asset_client) << "AssetRequest already started.";
return;
}
// in case we haven't parsed a valid hash, return an error now
if (isValidHash(_hash)) {
_result = InvalidHash;
_state = Finished;
emit finished(this);
return;
}
// Try to load from cache
_data = loadFromCache(getUrl());

View file

@ -34,6 +34,7 @@ public:
NoError,
NotFound,
InvalidByteRange,
InvalidHash,
HashVerificationFailed,
NetworkError,
UnknownError

View file

@ -109,15 +109,6 @@ void AssetResourceRequest::requestMappingForPath(const AssetPath& path) {
void AssetResourceRequest::requestHash(const AssetHash& hash) {
// in case we haven't parsed a valid hash, return an error now
if (hash.length() != SHA256_HASH_HEX_LENGTH) {
_result = InvalidURL;
_state = Finished;
emit finished();
return;
}
// Make request to atp
auto assetClient = DependencyManager::get<AssetClient>();
_assetRequest = assetClient->createRequest(hash);
@ -133,6 +124,9 @@ void AssetResourceRequest::requestHash(const AssetHash& hash) {
_data = req->getData();
_result = Success;
break;
case AssetRequest::InvalidHash:
_result = InvalidURL;
break;
case AssetRequest::Error::NotFound:
_result = NotFound;
break;