Debian Codegraph @

Server/Web/ResponseHtmlFull.cpp

raw symbols SCIP
1 /*
2 RailControl - Model Railway Control Software
3
4 Copyright (c) 2017-2025 by Teddy / Dominik Mahrer - www.railcontrol.org
5
6 RailControl is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any
9 later version.
10
11 RailControl is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with RailControl; see the file LICENCE. If not see
18 <http://www.gnu.org/licenses/>.
19 */
20
21 #include <sstream>
22 #include <string>
23
24 #include "Server/Web/ResponseHtmlFull.h"
25
26 namespace Server { namespace Web
27 {
28 ResponseHtmlFull::operator std::string()
29 {
30 std::stringstream reply;
31 reply << *this;
32 return reply.str();
33 }
34
35 std::ostream& operator<<(std::ostream& stream, const ResponseHtmlFull& response)
36 {
37 stream << "HTTP/1.1 " << std::to_string(response.responseCode) << " " << ResponseHtml::responseTexts.at(response.responseCode) << "\r\n";
38 for (auto& header : response.headers)
39 {
40 stream << header.first << ": " << header.second << "\r\n";
41 }
42
43 std::stringstream body;
44 body << "<!DOCTYPE html>";
45
46 HtmlTag head("head");
47 head.AddChildTag(HtmlTag("title").AddId("title").AddContent(response.title));
48 head.AddChildTag(HtmlTag("link").AddAttribute("rel", "stylesheet").AddAttribute("type", "text/css").AddAttribute("href", "/style.css"));
49 head.AddChildTag(HtmlTag("script").AddAttribute("type", "application/javascript").AddAttribute("src", "/nosleep.js"));
50 head.AddChildTag(HtmlTag("script").AddAttribute("type", "application/javascript").AddAttribute("src", "/javascript.js"));
51 head.AddChildTag(HtmlTag("meta").AddAttribute("name", "viewport").AddAttribute("content", "width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"));
52 head.AddChildTag(HtmlTag("meta").AddAttribute("name", "robots").AddAttribute("content", "noindex,nofollow"));
53
54 body << HtmlTag("html").AddChildTag(head).AddChildTag(response.content);
55
56 std::string bodyString(body.str());
57
58 stream << "Content-Length: " << bodyString.size();
59 stream << "\r\n\r\n";
60 stream << bodyString;
61 return stream;
62 }
63 }} // namespace Server::Web