diff --git a/src/output/output_http.cpp b/src/output/output_http.cpp index 42fcb607..c6d8c802 100644 --- a/src/output/output_http.cpp +++ b/src/output/output_http.cpp @@ -55,12 +55,13 @@ namespace Mist{ void HTTPOutput::onFail(const std::string &msg, bool critical){ INFO_MSG("Failing '%s': %s", H.url.c_str(), msg.c_str()); - if (!webSock && !isRecording()){ + if (!webSock && !isRecording() && !responded){ H.Clean(); // make sure no parts of old requests are left in any buffers H.SetHeader("Server", APPIDENT); H.setCORSHeaders(); H.SetBody("Could not retrieve stream: " + msg); H.SendResponse("404", "Error opening stream", myConn); + responded = true; } Output::onFail(msg, critical); } @@ -292,6 +293,7 @@ namespace Mist{ H.Clean(); return; } + responded = false; preHTTP(); onHTTP(); idleLast = Util::bootMS(); diff --git a/src/output/output_http.h b/src/output/output_http.h index d520802e..4d922593 100644 --- a/src/output/output_http.h +++ b/src/output/output_http.h @@ -27,6 +27,7 @@ namespace Mist{ protected: bool firstRun; + bool responded; HTTP::Parser H; HTTP::Websocket *webSock; uint32_t idleInterval; diff --git a/src/output/output_http_internal.cpp b/src/output/output_http_internal.cpp index 43768e05..4efa195d 100644 --- a/src/output/output_http_internal.cpp +++ b/src/output/output_http_internal.cpp @@ -63,6 +63,10 @@ namespace Mist{ bool OutHTTP::listenMode(){return !(config->getString("ip").size());} void OutHTTP::onFail(const std::string &msg, bool critical){ + if (responded){ + HTTPOutput::onFail(msg, critical); + return; + } std::string method = H.method; // send logo icon if (H.url.length() > 4 && H.url.substr(H.url.length() - 4, 4) == ".ico"){ @@ -92,10 +96,12 @@ namespace Mist{ H.setCORSHeaders(); if (method == "OPTIONS" || method == "HEAD"){ H.SendResponse("200", "OK", myConn); + responded = true; H.Clean(); return; } H.SendResponse("200", "Stream not found", myConn); + responded = true; H.Clean(); return; } @@ -379,6 +385,7 @@ namespace Mist{ H.setCORSHeaders(); if (method == "OPTIONS" || method == "HEAD"){ H.SendResponse("200", "OK", myConn); + responded = true; H.Clean(); return; } @@ -406,10 +413,12 @@ namespace Mist{ uAgent.find("OS 15") == std::string::npos && uAgent.find("OS 16") == std::string::npos){ H.SetHeader("Location", hlsUrl); H.SendResponse("307", "HLS redirect", myConn); + responded = true; return; } } H.SendResponse("200", "OK", myConn); + responded = true; } JSON::Value OutHTTP::getStatusJSON(std::string &reqHost, const std::string &useragent){ @@ -601,6 +610,7 @@ namespace Mist{ H.setCORSHeaders(); H.SetBody(it->asStringRef().substr(cbToken.size() + 1)); H.SendResponse("200", "OK", myConn); + responded = true; H.Clean(); return; } @@ -611,6 +621,7 @@ namespace Mist{ H.setCORSHeaders(); H.SetBody("No matching validation found for token '" + cbToken + "'"); H.SendResponse("404", "Not found", myConn); + responded = true; H.Clean(); return; } @@ -622,6 +633,7 @@ namespace Mist{ H.setCORSHeaders(); if (method == "OPTIONS" || method == "HEAD"){ H.SendResponse("200", "OK", myConn); + responded = true; H.Clean(); return; } @@ -630,6 +642,7 @@ namespace Mist{ "cross-domain-policy.dtd\">"); H.SendResponse("200", "OK", myConn); + responded = true; H.Clean(); return; }// crossdomain.xml @@ -641,6 +654,7 @@ namespace Mist{ H.setCORSHeaders(); if (method == "OPTIONS" || method == "HEAD"){ H.SendResponse("200", "OK", myConn); + responded = true; H.Clean(); return; } @@ -651,6 +665,7 @@ namespace Mist{ "uri=\"*\"/>"); H.SendResponse("200", "OK", myConn); + responded = true; H.Clean(); return; }// clientaccesspolicy.xml @@ -661,6 +676,7 @@ namespace Mist{ H.SetHeader("Server", APPIDENT); H.SetBody((const char *)FlashMediaPlayback_101_swf, FlashMediaPlayback_101_swf_len); H.SendResponse("200", "OK", myConn); + responded = true; return; } if (H.url == "/oldflashplayer.swf"){ @@ -669,6 +685,7 @@ namespace Mist{ H.SetHeader("Server", APPIDENT); H.SetBody((const char *)FlashMediaPlayback_swf, FlashMediaPlayback_swf_len); H.SendResponse("200", "OK", myConn); + responded = true; return; } // send logo icon @@ -725,12 +742,14 @@ namespace Mist{ H.setCORSHeaders(); if (method == "OPTIONS" || method == "HEAD"){ H.SendResponse("200", "OK", myConn); + responded = true; H.Clean(); return; } H.SetBody("\n \n \n \n \n \n" + trackSources + " \n \n"); H.SendResponse("200", "OK", myConn); + responded = true; H.Clean(); return; } @@ -754,6 +773,7 @@ namespace Mist{ } if (method == "OPTIONS" || method == "HEAD"){ H.SendResponse("200", "OK", myConn); + responded = true; H.Clean(); return; } @@ -766,6 +786,7 @@ namespace Mist{ } H.SetBody(response); H.SendResponse("200", "OK", myConn); + responded = true; H.Clean(); return; }// embed code generator @@ -790,6 +811,7 @@ namespace Mist{ H.SetHeader("Content-Type", "application/javascript; charset=utf-8"); if (method == "OPTIONS" || method == "HEAD"){ H.SendResponse("200", "OK", myConn); + responded = true; H.Clean(); return; } @@ -850,6 +872,7 @@ namespace Mist{ H.SetBody(response); H.SendResponse("200", "OK", myConn); + responded = true; H.Clean(); return; } @@ -863,6 +886,7 @@ namespace Mist{ H.SetHeader("Content-Type", "text/css"); if (method == "OPTIONS" || method == "HEAD"){ H.SendResponse("200", "OK", myConn); + responded = true; H.Clean(); return; } @@ -879,12 +903,14 @@ namespace Mist{ }else{ H.SetBody("Unknown stylesheet: " + url); H.SendResponse("404", "Unknown stylesheet", myConn); + responded = true; H.Clean(); return; } H.SetBody(response); H.SendResponse("200", "OK", myConn); + responded = true; H.Clean(); return; } @@ -896,6 +922,7 @@ namespace Mist{ H.SetHeader("Content-Type", "application/javascript"); if (method == "OPTIONS" || method == "HEAD"){ H.SendResponse("200", "OK", myConn); + responded = true; H.Clean(); return; } @@ -905,6 +932,7 @@ namespace Mist{ H.SetBody(response); H.SendResponse("200", "OK", myConn); + responded = true; H.Clean(); return; } @@ -916,6 +944,7 @@ namespace Mist{ H.SetHeader("Content-Type", "application/javascript"); if (method == "OPTIONS" || method == "HEAD"){ H.SendResponse("200", "OK", myConn); + responded = true; H.Clean(); return; } @@ -927,6 +956,7 @@ namespace Mist{ H.SetBody(response); H.SendResponse("200", "OK", myConn); + responded = true; H.Clean(); return; } @@ -938,6 +968,7 @@ namespace Mist{ H.SetHeader("Content-Type", "application/javascript"); if (method == "OPTIONS" || method == "HEAD"){ H.SendResponse("200", "OK", myConn); + responded = true; H.Clean(); return; } @@ -947,6 +978,7 @@ namespace Mist{ H.SetBody(response); H.SendResponse("200", "OK", myConn); + responded = true; H.Clean(); return; } @@ -981,11 +1013,13 @@ namespace Mist{ H.setCORSHeaders(); if (method == "OPTIONS" || method == "HEAD"){ H.SendResponse("200", "OK", myConn); + responded = true; H.Clean(); return; } H.SetBody("Yup"); H.SendResponse("200", "OK", myConn); + responded = true; H.Clean(); return; } @@ -998,10 +1032,12 @@ namespace Mist{ H.setCORSHeaders(); if (method == "OPTIONS" || method == "HEAD"){ H.SendResponse("200", "OK", myConn); + responded = true; H.Clean(); return; } H.SendResponse("200", "OK", myConn); + responded = true; myConn.SendNow((const char *)icon_data, icon_len); H.Clean(); }