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 <ctime>
53#include <map>
54#include <string>
55#include <utility>
56#include <vector>
57
58// IWYU pragma: no_include <iterator>
59// IWYU pragma: no_include <bits/types/struct_tm.h>
60
61#endif /* DOXYGEN_SHOULD_SKIP_THIS */
62
63namespace httputils {
64
65 std::string url_decode(const std::string& text);
66
67 std::string url_encode(const std::string& text);
68
69 std::string& str_trimm(std::string& text);
70
71 std::pair<std::string, std::string> str_split(const std::string& base, char c_middle);
72
73 std::pair<std::string, std::string> str_split_last(const std::string& base, char c_middle);
74
75 std::string to_http_date(struct tm* tm = nullptr);
76
77 struct tm from_http_date(const std::string& http_date);
78
79 std::string file_mod_http_date(const std::string& filePath);
80
81 std::string::iterator to_lower(std::string& string);
82
83 std::string toString(const std::string& method,
84 const std::string& url,
85 const std::string& version,
86 const std::map<std::string, std::string>& queries,
87 const web::http::CiStringMap<std::string>& header,
88 const web::http::CiStringMap<std::string>& trailer,
89 const web::http::CiStringMap<std::string>& cookies,
90 const std::vector<char>& body);
91
92 std::string toString(const std::string& version,
93 const std::string& statusCode,
94 const std::string& reason,
95 const web::http::CiStringMap<std::string>& header,
96 const web::http::CiStringMap<web::http::CookieOptions>& cookies,
97 const std::vector<char>& body);
98
99} // namespace httputils
100
101#endif // WEB_HTTP_UTILS_H
#define MIDDLEWARE(req, res, next)
Definition Router.h:63
const std::string & getConnectionName() const
SocketConnection * getSocketConnection() const
void operator()(const std::string &how="") const
Definition Next.cpp:56
std::string url
Definition Request.h:98
std::string originalPath
Definition Request.h:78
std::string method
Definition Request.h:97
std::string path
Definition Request.h:79
Response & cookie(const std::string &name, const std::string &value, const std::map< std::string, std::string > &options={})
Definition Response.cpp:147
void redirect(int state, const std::string &loc, const std::string &html={})
Definition Response.cpp:90
void sendFile(const std::string &file, const std::function< void(int)> &callback)
Definition Response.cpp:181
void sendStatus(int state, const std::string &html={})
Definition Response.cpp:95
Response & set(const std::string &field, const std::string &value, bool overwrite=true)
Definition Response.cpp:129
void send(const std::string &chunk)
Definition Response.cpp:169
Response & status(int status)
Definition Response.cpp:117
Response & set(const std::map< std::string, std::string > &headers, bool overwrite=true)
Definition Response.cpp:135
web::http::server::SocketContext * getSocketContext() const
Definition Response.cpp:68
const Router & setStrictRouting(bool strictRouting=true) const
Definition Router.cpp:78
std::map< std::string, web::http::CookieOptions > stdCookies
StaticMiddleware & setIndex(const std::string &index)
StaticMiddleware & appendStdHeaders(const std::string &field, const std::string &value)
web::http::ConnectionState defaultConnectionState
std::map< std::string, std::string > stdHeaders
static class StaticMiddleware & instance(const std::string &root)
StaticMiddleware(const std::string &root)
StaticMiddleware & afterResponse(web::http::ConnectionState connectionState)
const std::map< std::string, std::string > & getOptions() const
CookieOptions(const std::string &value, const std::map< std::string, std::string > &options)
const std::string & getValue() const
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 to_http_date(struct tm *tm=nullptr)
struct tm from_http_date(const std::string &http_date)
std::string toString(const std::string &method, const std::string &url, const std::string &version, const std::map< std::string, std::string > &queries, const web::http::CiStringMap< std::string > &header, const web::http::CiStringMap< std::string > &trailer, const web::http::CiStringMap< std::string > &cookies, const std::vector< char > &body)