From d9c98f3a731e6a00f10fb3fbe88b45ec2a385e63 Mon Sep 17 00:00:00 2001 From: Miguel Freitas Date: Sun, 20 Oct 2013 14:41:55 -0200 Subject: [PATCH] add some mime types to the lame web server --- src/bitcoinrpc.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 14660750..272b6ca8 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -979,11 +979,23 @@ void ServiceConnection(AcceptedConnection *conn) std::vector file_data; if( load_file(strURI.c_str(), file_data) == 0 ) { std::string str(file_data.data(), file_data.size()); - conn->stream() << HTTPReply(HTTP_OK, str, false, "text/html") << std::flush; + const char *contentType = "text/html"; + if( strURI.find(".js") != std::string::npos ) + contentType = "text/javascript"; + if( strURI.find(".css") != std::string::npos ) + contentType = "text/css"; + if( strURI.find(".png") != std::string::npos ) + contentType = "image/png"; + if( strURI.find(".ttf") != std::string::npos ) + contentType = "application/x-font-ttf"; + if( strURI.find(".jpg") != std::string::npos || + strURI.find(".jpeg") != std::string::npos ) + contentType = "image/jpeg"; + conn->stream() << HTTPReply(HTTP_OK, str, false, contentType) << std::flush; } else { conn->stream() << HTTPReply(HTTP_NOT_FOUND, "", false) << std::flush; } - break; + continue; } // Check authorization