Bugfix: Return 404 if fallback is empty or unknown

This commit is contained in:
tastytea 2018-11-27 05:15:35 +01:00
parent 50d902bcc9
commit 8cc6e73cb1
Signed by untrusted user: tastytea
GPG Key ID: CFC39497F1B26E07
2 changed files with 22 additions and 24 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.2)
project(libravatarserv
VERSION 0.4.2
VERSION 0.4.3
LANGUAGES CXX
)

View File

@ -62,33 +62,31 @@ int main()
else
{
cerr << "Error " << std::to_string(image.error) << ": Could not open file.\n";
if (avatar.fallback.empty() || avatar.fallback == "404")
if (avatar.fallback.substr(0, 4) == "http")
{
cout << "Status: 404 Not Found\n\n";
cout << "Status: 307 Temporary Redirect\n";
cout << "Location: " << avatar.fallback << endl << endl;
}
else if (avatar.fallback.substr(0, 2) == "mp" ||
avatar.fallback.substr(0, 2) == "mm")
{
// MD5 hash of 'mp'
image = image::get("1f2dfa567dcf95833eddf7aec167fec7",
avatar.size);
if (image.error == 0)
{
image::write(image);
}
else
{
cout << "Status: 404 Not Found\n\n";
cerr << "Mystery person not found.\n";
}
}
else
{
if (avatar.fallback.substr(0, 4) == "http")
{
cout << "Status: 307 Temporary Redirect\n";
cout << "Location: " << avatar.fallback << endl << endl;
}
else if (avatar.fallback.substr(0, 2) == "mp" ||
avatar.fallback.substr(0, 2) == "mm")
{
// MD5 hash of 'mp'
image = image::get("1f2dfa567dcf95833eddf7aec167fec7",
avatar.size);
if (image.error == 0)
{
image::write(image);
}
else
{
cout << "Status: 404 Not Found\n\n";
cerr << "Mystery person not found.\n";
}
}
// If fallback is empty or unknown
cout << "Status: 404 Not Found\n\n";
}
}