Debian Codegraph @

Server/Web/ResponseCsv.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/ResponseCsv.h"
25
26 namespace Server { namespace Web
27 {
28 ResponseCsv::ResponseCsv(const std::string& content)
29 : Response(),
30 csvContent(content)
31 {
32 AddHeader("Cache-Control", "no-cache, must-revalidate");
33 AddHeader("Pragma", "no-cache");
34 AddHeader("Expires", "Sun, 12 Feb 2016 00:00:00 GMT");
35 AddHeader("Content-Type", "text/csv; charset=utf-8");
36 AddHeader("Connection", "keep-alive");
37 }
38
39 ResponseCsv::operator std::string()
40 {
41 std::stringstream reply;
42 reply << *this;
43 return reply.str();
44 }
45
46 std::ostream& operator<<(std::ostream& stream, const ResponseCsv& response)
47 {
48 stream << "HTTP/1.1 " << std::to_string(response.responseCode) << " " << Response::responseTexts.at(response.responseCode) << "\r\n";
49 for (auto& header : response.headers)
50 {
51 stream << header.first << ": " << header.second << "\r\n";
52 }
53
54 stream << "Content-Length: " << response.csvContent.size();
55 stream << "\r\n\r\n";
56 stream << response.csvContent;
57 return stream;
58 }
59 }} // namespace Server::Web