Added support for all common content-types into MHDFilestreamerHandler

File extension --> content-type associations are read from mime.types file.
This commit is contained in:
hunbernd 2015-11-06 22:05:35 +01:00
parent bdc70c6561
commit ce40760791
4 changed files with 96 additions and 4 deletions

View file

@ -7,6 +7,7 @@
#include <algorithm>
#include <util/rsdir.h>
#include "util/ContentTypes.h"
// for filestreamer
#include <retroshare/rsfiles.h>
@ -302,8 +303,13 @@ public:
struct MHD_Response* resp = MHD_create_response_from_callback(
mSize, 1024*1024, &contentReadercallback, this, NULL);
// only mp3 at the moment
MHD_add_response_header(resp, "Content-Type", "audio/mpeg3");
// get content-type from extension
std::string ext = "";
unsigned int i = info.fname.rfind('.');
if(i != std::string::npos)
ext = info.fname.substr(i+1);
MHD_add_response_header(resp, "Content-Type", ContentTypes::ContentTypes::cTypeFromExt(ext).c_str());
secure_queue_response(connection, MHD_HTTP_OK, resp);
MHD_destroy_response(resp);
return MHD_YES;