From 8fa8a5d7367fa9d683fa070cd557dae552f7c7f1 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Thu, 11 Dec 2014 12:23:19 +0100 Subject: [PATCH] Fixed JSON error responses to internal HTTP output. --- src/output/output_http.h | 2 +- src/output/output_http_internal.cpp | 17 +++++++++++++++++ src/output/output_http_internal.h | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/output/output_http.h b/src/output/output_http.h index 2b8a372c..272c68ce 100644 --- a/src/output/output_http.h +++ b/src/output/output_http.h @@ -10,7 +10,7 @@ namespace Mist { virtual ~HTTPOutput(){}; static void init(Util::Config * cfg); void onRequest(); - void onFail(); + virtual void onFail(); virtual void onHTTP(){}; virtual void requestHandler(); static bool listenMode(){return false;} diff --git a/src/output/output_http_internal.cpp b/src/output/output_http_internal.cpp index da2f8cb8..02d44cee 100644 --- a/src/output/output_http_internal.cpp +++ b/src/output/output_http_internal.cpp @@ -19,6 +19,23 @@ namespace Mist { return !(config->getString("ip").size()); } + void OutHTTP::onFail(){ + INFO_MSG("Failing: %s", H.url.c_str()); + if (H.url.size() >= 3 && H.url.substr(H.url.size() - 3) == ".js"){ + if (H.url.size() >= 5 && H.url.substr(0, 5) == "/json"){ + H.Clean(); + H.SetBody("{\"error\":\"Could not retrieve stream. Sorry.\"}\n"); + }else{ + H.Clean(); + H.SetBody("mistvideo['" + streamName + "'] = {\"error\":\"Could not retrieve stream. Sorry.\"};\n"); + } + H.SendResponse("200", "Stream not found", myConn); + }else{ + HTTPOutput::onFail(); + } + Output::onFail(); + } + void OutHTTP::init(Util::Config * cfg){ HTTPOutput::init(cfg); capa.removeMember("deps"); diff --git a/src/output/output_http_internal.h b/src/output/output_http_internal.h index 3154ff72..4f025afa 100644 --- a/src/output/output_http_internal.h +++ b/src/output/output_http_internal.h @@ -8,6 +8,7 @@ namespace Mist { ~OutHTTP(); static void init(Util::Config * cfg); static bool listenMode(); + virtual void onFail(); void onHTTP(); }; }