From 7efec890f7312ff85a5fe7c0b108b5c821012b61 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 25 Nov 2018 08:35:43 +0100 Subject: [PATCH] Return 404 if image is not found --- CMakeLists.txt | 2 +- src/libravatarserv.cpp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6098f71..16add35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.2) project(libravatarserv - VERSION 0.2.3 + VERSION 0.2.4 LANGUAGES CXX ) diff --git a/src/libravatarserv.cpp b/src/libravatarserv.cpp index 10b47e5..f87f69e 100644 --- a/src/libravatarserv.cpp +++ b/src/libravatarserv.cpp @@ -55,8 +55,6 @@ int main() cerr << "Error: Invalid URL.\n"; return 1; } - cout << "Content-type: image/png\n\n"; - cout.flush(); // We need to flush before we use /dev/stdout directly. uint16_t size = 80; string digest = request.substr(8); @@ -75,11 +73,14 @@ int main() image::Image answer = image::get(digest, size); if (answer.error == 0) { + cout << "Content-type: image/png\n\n"; + cout.flush(); // We need to flush before we use /dev/stdout directly. // answer.image.write("test.png"); answer.image.write("/dev/stdout"); } else { + cout << "Status: 404 Not Found\n\n"; cerr << "Error " << std::to_string(answer.error) << ": Could not open file.\n"; }