diff --git a/src/output/output_http_internal.cpp b/src/output/output_http_internal.cpp index 636fc9b0..c822cfd2 100644 --- a/src/output/output_http_internal.cpp +++ b/src/output/output_http_internal.cpp @@ -8,6 +8,33 @@ #include namespace Mist { + /// Helper function to find the protocol entry for a given port number + std::string getProtocolForPort(uint16_t portNo){ + std::string ret; + IPC::semaphore configLock(SEM_CONF, O_CREAT | O_RDWR, ACCESSPERMS, 1); + configLock.wait(); + IPC::sharedPage serverCfg(SHM_CONF, DEFAULT_CONF_PAGE_SIZE); + DTSC::Scan prtcls = DTSC::Scan(serverCfg.mapped, serverCfg.len).getMember("config").getMember("protocols"); + unsigned int pro_cnt = prtcls.getSize(); + for (unsigned int i = 0; i < pro_cnt; ++i){ + DTSC::Scan capa = DTSC::Scan(serverCfg.mapped, serverCfg.len).getMember("capabilities").getMember("connectors").getMember(prtcls.getIndice(i).getMember("connector").asString()); + uint16_t port = prtcls.getIndice(i).getMember("port").asInt(); + //get the default port if none is set + if (!port){ + port = capa.getMember("optional").getMember("port").getMember("default").asInt(); + } + if (port == portNo){ + ret = capa.getMember("protocol").asString(); + break; + } + } + configLock.post(); + if (ret.find(':') != std::string::npos){ + ret.erase(ret.find(':')); + } + return ret; + } + OutHTTP::OutHTTP(Socket::Connection & conn) : HTTPOutput(conn){ stayConnected = false; if (myConn.getPureSocket() >= 0){ @@ -272,6 +299,9 @@ namespace Mist { void OutHTTP::HTMLResponse(){ std::string method = H.method; HTTP::URL fullURL(H.GetHeader("Host")); + if (!fullURL.protocol.size()){ + fullURL.protocol = getProtocolForPort(fullURL.getPort()); + } /*LTS-START*/ if (config->getString("pubaddr") != ""){ HTTP::URL altURL(config->getString("pubaddr")); @@ -456,7 +486,6 @@ namespace Mist { return json_resp; } - void OutHTTP::onHTTP(){ std::string method = H.method; @@ -624,6 +653,9 @@ namespace Mist { if (H.url == "/player.js"){ HTTP::URL fullURL(H.GetHeader("Host")); + if (!fullURL.protocol.size()){ + fullURL.protocol = getProtocolForPort(fullURL.getPort()); + } /*LTS-START*/ if (config->getString("pubaddr") != ""){ HTTP::URL altURL(config->getString("pubaddr"));