SNode.C
Loading...
Searching...
No Matches
SocketContextUpgradeFactory.h
Go to the documentation of this file.
1/*
2 * SNode.C - A Slim Toolkit for Network Communication
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2020, 2021, 2022, 2023, 2024, 2025
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20/*
21 * MIT License
22 *
23 * Permission is hereby granted, free of charge, to any person obtaining a copy
24 * of this software and associated documentation files (the "Software"), to deal
25 * in the Software without restriction, including without limitation the rights
26 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27 * copies of the Software, and to permit persons to whom the Software is
28 * furnished to do so, subject to the following conditions:
29 *
30 * The above copyright notice and this permission notice shall be included in
31 * all copies or substantial portions of the Software.
32 *
33 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
39 * THE SOFTWARE.
40 */
41
42#ifndef WEB_HTTP_SERVER_SOCKETCONTEXTUPGRADEFACTORY_H
43#define WEB_HTTP_SERVER_SOCKETCONTEXTUPGRADEFACTORY_H
44
45#include "web/http/SocketContextUpgradeFactory.h" // IWYU pragma: export
46
47namespace web::http::server {
48 class Request;
49 class Response;
50} // namespace web::http::server
51
52#ifndef DOXYGEN_SHOULD_SKIP_THIS
53
54#include <string> // for string
55
56#endif /* DOXYGEN_SHOULD_SKIP_THIS */
57
58namespace web::http::server {
59
61 : public web::http::SocketContextUpgradeFactory<web::http::server::Request, web::http::server::Response> {
62 public:
63 using Resquest = web::http::server::Request;
64 using Reponse = web::http::server::Response;
65
66 protected:
68
69 public:
70 void checkRefCount() final;
71
72 static void link(const std::string& upgradeContextName, SocketContextUpgradeFactory* (*linkedPlugin)());
73
75 };
76
77} // namespace web::http::server
78
79extern template class web::http::SocketContextUpgradeFactory<web::http::server::Request, web::http::server::Response>;
80
81#endif // WEB_HTTP_SERVER_SOCKETCONTEXTUPGRADEFACTORY_H
static FileReader * open(const std::string &path)
void stop()
Definition Sink.cpp:68
bool isStreaming()
Definition Sink.cpp:64
virtual void stop()=0
void pipe(Sink *sink, const std::function< void(int)> &callback)
Definition Source.cpp:60
virtual void start()=0
void sendToPeer(const std::string &data) const
const std::string & getConnectionName() const
SocketConnection * getSocketConnection() const
virtual void switchSocketContext(SocketContext *newSocketContext)
void sendToPeer(const char *chunk, std::size_t chunkLen) const final
bool streamToPeer(core::pipe::Source *source) const
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
static std::string contentType(const std::string &file)
core::socket::stream::SocketContext * create(core::socket::stream::SocketConnection *socketConnection) final
static std::string reason(int status)
const std::string & get(const std::string &key, int i=0) const
Definition Request.cpp:53
void onSourceData(const char *chunk, std::size_t chunkLen) override
Definition Response.cpp:430
Response(SocketContext *socketContext)
Definition Response.cpp:72
SocketContext * getSocketContext() const
Definition Response.cpp:457
SocketContext * socketContext
Definition Response.h:137
void onSourceConnect(core::pipe::Source *source) override
Definition Response.cpp:416
web::http::CiStringMap< web::http::CookieOptions > cookies
Definition Response.h:130
Response & status(int statusCode)
Definition Response.cpp:102
void send(const std::string &chunk)
Definition Response.cpp:224
void send(const char *chunk, std::size_t chunkLen)
Definition Response.cpp:213
Response & setTrailer(const std::string &field, const std::string &value, bool overwrite=true)
Definition Response.cpp:194
Response & set(const std::map< std::string, std::string > &headers, bool overwrite=true)
Definition Response.cpp:120
web::http::CiStringMap< std::string > trailer
Definition Response.h:131
web::http::CiStringMap< std::string > headers
Definition Response.h:129
Response & set(const std::string &field, const std::string &value, bool overwrite=true)
Definition Response.cpp:128
TransferEncoding transferEncoding
Definition Response.h:141
void upgrade(const std::shared_ptr< Request > &request, const std::function< void(const std::string &)> &status)
Definition Response.cpp:244
Response & type(const std::string &type)
Definition Response.cpp:174
void onSourceError(int errnum) override
Definition Response.cpp:442
core::socket::stream::SocketContext * socketContextUpgrade
Definition Response.h:138
Response & sendFragment(const std::string &chunk)
Definition Response.cpp:389
Response & cookie(const std::string &name, const std::string &value, const std::map< std::string, std::string > &options={})
Definition Response.cpp:178
Response & append(const std::string &field, const std::string &value)
Definition Response.cpp:108
void sendStatus(int statusCode)
Definition Response.cpp:232
Response & sendFragment(const char *chunk, std::size_t chunkLen)
Definition Response.cpp:371
void onSourceEof() override
Definition Response.cpp:434
void sendFile(const std::string &file, const std::function< void(int)> &callback)
Definition Response.cpp:292
Response & clearCookie(const std::string &name, const std::map< std::string, std::string > &options={})
Definition Response.cpp:184
ConnectionState connectionState
Definition Response.h:140
const std::string & header(const std::string &field)
Definition Response.cpp:453
SocketContextUpgradeFactory * select(Request &req, Response &res) override
SocketContextUpgradeFactory * load(const std::string &socketContextUpgradeName) override
static void link(const std::string &upgradeContextName, SocketContextUpgradeFactory *(*linkedPlugin)())
std::string to_http_date(struct tm *tm)
std::string file_mod_http_date(const std::string &filePath)
struct tm * gmtime(const time_t *timep)
Definition time.cpp:62
bool ciEquals(const std::string &str1, const std::string &str2)
bool ciContains(const std::string &str1, const std::string &str2)
#define to_hex_str(int_val)
Definition Request.cpp:71