SNode.C
Loading...
Searching...
No Matches
http_utils.h
Go to the documentation of this file.
1/*
2 * SNode.C - A Slim Toolkit for Network Communication
3 * Copyright (C) 2020, 2021 Volker Christian <me@vchrist.at>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/*
20 * MIT License
21 *
22 * Permission is hereby granted, free of charge, to any person obtaining a copy
23 * of this software and associated documentation files (the "Software"), to deal
24 * in the Software without restriction, including without limitation the rights
25 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26 * copies of the Software, and to permit persons to whom the Software is
27 * furnished to do so, subject to the following conditions:
28 *
29 * The above copyright notice and this permission notice shall be included in
30 * all copies or substantial portions of the Software.
31 *
32 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
38 * THE SOFTWARE.
39 */
40
41#ifndef WEB_HTTP_UTILS_H
42#define WEB_HTTP_UTILS_H
43
44#ifndef DOXYGEN_SHOULD_SKIP_THIS
45
46namespace web::http {
47 class CookieOptions;
48 template <typename ValueT>
49 class CiStringMap;
50} // namespace web::http
51
52#include <string>
53#include <time.h>
54#include <utility>
55#include <vector>
56
57// IWYU pragma: no_include <bits/types/struct_tm.h>
58
59#endif /* DOXYGEN_SHOULD_SKIP_THIS */
60
61namespace httputils {
62
63 std::string url_decode(const std::string& text);
64
65 std::string url_encode(const std::string& text);
66
67 std::string& str_trimm(std::string& text);
68
69 std::pair<std::string, std::string> str_split(const std::string& base, char c_middle);
70
71 std::pair<std::string, std::string> str_split_last(const std::string& base, char c_middle);
72
73 std::string to_http_date(struct tm* tm = nullptr);
74
75 struct tm from_http_date(const std::string& http_date);
76
77 std::string file_mod_http_date(const std::string& filePath);
78
79 std::string::iterator to_lower(std::string& string);
80
81 std::string toString(const std::string& method,
82 const std::string& url,
83 const std::string& version,
84 const web::http::CiStringMap<std::string>& queries,
85 const web::http::CiStringMap<std::string>& header,
86 const web::http::CiStringMap<std::string>& cookies,
87 const std::vector<char>& body);
88
89 std::string toString(const std::string& version,
90 const std::string& statusCode,
91 const std::string& reason,
92 const web::http::CiStringMap<std::string>& header,
93 const web::http::CiStringMap<web::http::CookieOptions>& cookies,
94 const std::vector<char>& body);
95
96} // namespace httputils
97
98#endif // WEB_HTTP_UTILS_H
std::string to_http_date(struct tm *tm)
std::string toString(const std::string &version, const std::string &statusCode, const std::string &reason, const web::http::CiStringMap< std::string > &header, const web::http::CiStringMap< web::http::CookieOptions > &cookies, const std::vector< char > &body)
std::string url_encode(const std::string &text)
std::string file_mod_http_date(const std::string &filePath)
std::string::iterator to_lower(std::string &string)
std::pair< std::string, std::string > str_split_last(const std::string &base, char c_middle)
std::string url_decode(const std::string &text)
std::pair< std::string, std::string > str_split(const std::string &base, char c_middle)
std::string & str_trimm(std::string &text)
std::string toString(const std::string &method, const std::string &url, const std::string &version, const web::http::CiStringMap< std::string > &queries, const web::http::CiStringMap< std::string > &header, const web::http::CiStringMap< std::string > &cookies, const std::vector< char > &body)