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#ifndef WEB_HTTP_SOCKETCONTEXTUPGRADEFACTORY_H
21#define WEB_HTTP_SOCKETCONTEXTUPGRADEFACTORY_H
22
23#include "core/socket/stream/SocketContextFactory.h"
24
25namespace core::socket::stream {
26 class SocketConnection;
27 namespace stream {
28 class SocketContext;
29 }
30} // namespace core::socket::stream
31
32namespace web::http {
33 template <typename RequestT, typename ResponseT>
34 class SocketContextUpgrade;
35} // namespace web::http
36
37#ifndef DOXYGEN_SHOULD_SKIP_THIS
38
39#include <string>
40
41#endif /* DOXYGEN_SHOULD_SKIP_THIS */
42
43namespace web::http {
44
45 template <typename RequestT, typename ResponseT>
46 class SocketContextUpgradeFactory : public core::socket::stream::SocketContextFactory {
47 public:
48 using Request = RequestT;
49 using Response = ResponseT;
50
51 protected:
52 SocketContextUpgradeFactory() = default;
53 ~SocketContextUpgradeFactory() override = default;
54
55 public:
56 virtual std::string name() = 0;
57
58 protected:
59 std::size_t refCount = 0;
60
61 void prepare(Request& request, Response& response);
62
63 private:
64 virtual SocketContextUpgrade<Request, Response>*
65 create(core::socket::stream::SocketConnection* socketConnection, Request* request, Response* response) = 0;
66 core::socket::stream::SocketContext* create(core::socket::stream::SocketConnection* socketConnection) final;
67
68 void incRefCount();
69 void decRefCount();
70
71 virtual void checkRefCount() = 0;
72
73 Request* request = nullptr;
74 Response* response = nullptr;
75
76 friend Response;
77 friend Request;
78 friend class SocketContextUpgrade<Request, Response>;
79 };
80
81} // namespace web::http
82
83#endif // WEB_HTTP_SOCKETCONTEXTUPGRADEFACTORY_H
virtual void stop()=0
virtual void start()=0
Request & set(const std::string &field, const std::string &value, bool overwrite=true)
Definition Request.cpp:137
void onSourceEof() override
Definition Request.cpp:597
Request & cookie(const std::string &name, const std::string &value)
Definition Request.cpp:197
Request(Request &&) noexcept
Definition Request.cpp:59
void onSourceError(int errnum) override
Definition Request.cpp:605
std::string header(const std::string &field)
Definition Request.cpp:616
Request & sendFragment(const std::string &data)
Definition Request.cpp:390
bool sendFile(const std::string &file, const std::function< void(int errnum)> &onStatus, const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> &onResponseReceived, const std::function< void(const std::shared_ptr< Request > &, const std::string &)> &onResponseParseError=responseParseError)
Definition Request.cpp:352
Request & query(const std::string &key, const std::string &value)
Definition Request.cpp:211
bool upgrade(const std::string &url, const std::string &protocols, const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> &onResponseReceived, const std::function< void(const std::shared_ptr< Request > &, const std::string &)> &onResponseParseError=responseParseError)
Definition Request.cpp:279
void onSourceData(const char *chunk, std::size_t chunkLen) override
Definition Request.cpp:593
bool executeSendFragment(const char *chunk, std::size_t chunkLen)
Definition Request.cpp:537
const CiStringMap< std::string > & getQueries() const
Definition Request.cpp:620
const CiStringMap< std::string > & getCookies() const
Definition Request.cpp:628
Request & setTrailer(const std::string &field, const std::string &value, bool overwrite=true)
Definition Request.cpp:217
Request & cookie(const std::map< std::string, std::string > &cookies)
Definition Request.cpp:203
web::http::client::SocketContext * getSocketContext() const
Definition Request.cpp:632
void setMasterRequest(const std::shared_ptr< Request > &masterRequest)
Definition Request.cpp:91
Request & set(const std::map< std::string, std::string > &headers, bool overwrite=true)
Definition Request.cpp:183
Request & append(const std::string &field, const std::string &value)
Definition Request.cpp:125
Request & sendFragment(const char *chunk, std::size_t chunkLen)
Definition Request.cpp:380
bool send(const char *chunk, std::size_t chunkLen, const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> &onResponseReceived, const std::function< void(const std::shared_ptr< Request > &, const std::string &)> &onResponseParseError=responseParseError)
Definition Request.cpp:242
const CiStringMap< std::string > & getHeaders() const
Definition Request.cpp:624
Request & host(const std::string &hostFieldValue)
Definition Request.cpp:119
bool send(const std::string &chunk, const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> &onResponseReceived, const std::function< void(const std::shared_ptr< Request > &, const std::string &)> &onResponseParseError=responseParseError)
Definition Request.cpp:269
Request & type(const std::string &type)
Definition Request.cpp:191
bool end(const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> &onResponseReceived, const std::function< void(const std::shared_ptr< Request > &, const std::string &)> &onResponseParseError=responseParseError)
Definition Request.cpp:394
void deliverResponseParseError(const std::shared_ptr< Request > &request, const std::string &message)
Definition Request.cpp:562
bool executeSendFile(const std::string &file, const std::function< void(int)> &onStatus)
Definition Request.cpp:439
bool executeUpgrade(const std::string &url, const std::string &protocols)
Definition Request.cpp:481
#define to_hex_str(int_val)
Definition Request.cpp:49