Commit f55221a9 authored by Hubert Denkmair's avatar Hubert Denkmair
Browse files

handle invalid requests better

parent a5ce9064
Loading
Loading
Loading
Loading
+15 −8
Original line number Diff line number Diff line
@@ -72,13 +72,14 @@ int RelayServer::Run()

	h.onMessage([](uWS::WebSocket<uWS::SERVER> *ws, char *message, size_t length, uWS::OpCode opCode)
	{	
		auto *con = static_cast<WebsocketConnection*>(ws->getUserData());

		if (length>MAX_CLIENT_MESSAGE_SIZE)
		{
			ws->close(413, "payload to large");
			return;
		}

		try {
			auto *con = static_cast<WebsocketConnection*>(ws->getUserData());
			std::string s(message, length);
			json data = json::parse(s, nullptr, false);
			if (!data.is_object()) { return; }
@@ -88,6 +89,12 @@ int RelayServer::Run()
				std::string key = data["viewer_key"];
				con->setViewerKey(static_cast<uint64_t>(std::stol(key)));
			}
		}
		catch (std::exception e)
		{
			ws->close(418, "invalid request");
			return;
		}
	});

	std::string response = "Hello!";