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_CLIENT_SOCKETCONTEXTUPGRADEFACTORY_H
43#define WEB_HTTP_CLIENT_SOCKETCONTEXTUPGRADEFACTORY_H
44
45#include "web/http/SocketContextUpgradeFactory.h" // IWYU pragma: export
46// IWYU pragma: no_include "web/http/SocketContextUpgradeFactory.hpp"
47
48namespace web::http::client {
49 class Request;
50 class Response;
51} // namespace web::http::client
52
53#ifndef DOXYGEN_SHOULD_SKIP_THIS
54
55#include <string>
56
57#endif /* DOXYGEN_SHOULD_SKIP_THIS */
58
59namespace web::http::client {
60
62 : public web::http::SocketContextUpgradeFactory<web::http::client::Request, web::http::client::Response> {
63 public:
64 using Resquest = web::http::client::Request;
65 using Reponse = web::http::client::Response;
66
67 protected:
69
70 using web::http::SocketContextUpgradeFactory<Request, Response>::prepare;
71 virtual void prepare(Request& request) = 0;
72
73 public:
74 void checkRefCount() final;
75
76 static void link(const std::string& upgradeContextName, SocketContextUpgradeFactory* (*linkedPlugin)());
77
79 };
80
81} // namespace web::http::client
82
83extern template class web::http::SocketContextUpgradeFactory<web::http::client::Request, web::http::client::Response>;
84
85#endif // WEB_HTTP_CLIENT_SOCKETCONTEXTUPGRADEFACTORY_H
static FileReader * open(const std::string &path)
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
static std::string contentType(const std::string &file)
MimeTypes operator=(const MimeTypes &)=delete
MimeTypes(const MimeTypes &)=delete
static std::map< std::string, std::string > mimeType
Definition MimeTypes.h:76
void link(const std::string &socketContextUpgradeName, SocketContextUpgradeFactory *(*linkedPlugin)())
bool add(SocketContextUpgradeFactory *socketContextUpgradeFactory, void *handler)
virtual SocketContextUpgradeFactory * select(Request &req, Response &res)=0
std::map< std::string, SocketContextUpgradeFactory *(*)()> linkedSocketContextUpgradePlugins
virtual SocketContextUpgradeFactory * load(const std::string &socketContextUpgradeName)=0
SocketContextUpgradeFactory * select(const std::string &socketContextUpgradeName)
void unload(SocketContextUpgradeFactory *socketContextUpgradeFactory)
SocketContextUpgradeFactory * load(const std::string &socketContextUpgradeName, const std::string &socketContextUpgradeFactoryLibraryFile, const std::string &socketContextUpgradeFactoryFunctionName)
bool add(SocketContextUpgradeFactory *socketContextUpgradeFactory)
std::map< std::string, SocketContextPlugin > socketContextUpgradePlugins
void prepare(Request &request, Response &response)
core::socket::stream::SocketContext * create(core::socket::stream::SocketConnection *socketConnection) final
~SocketContextUpgradeFactory() override=default
virtual SocketContextUpgrade< Request, Response > * create(core::socket::stream::SocketConnection *socketConnection, Request *request, Response *response)=0
SocketContextUpgrade(core::socket::stream::SocketConnection *socketConnection, SocketContextUpgradeFactory *socketContextUpgradeFactory)
SocketContextUpgradeFactory * socketContextUpgradeFactory
virtual bool execute(Request *request)=0
CiStringMap< std::string > headers
Definition Request.h:172
Request & set(const std::string &field, const std::string &value, bool overwrite=true)
Definition Request.cpp:159
TransferEncoding transferEncoding
Definition Request.h:179
ConnectionState connectionState
Definition Request.h:184
std::size_t contentLengthSent
Definition Request.h:182
void onSourceEof() override
Definition Request.cpp:619
CiStringMap< std::string > cookies
Definition Request.h:173
Request & cookie(const std::string &name, const std::string &value)
Definition Request.cpp:219
Request(Request &&) noexcept
Definition Request.cpp:81
CiStringMap< std::string > trailer
Definition Request.h:174
void onSourceError(int errnum) override
Definition Request.cpp:627
std::string header(const std::string &field)
Definition Request.cpp:638
std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> onResponseReceived
Definition Request.h:186
Request & sendFragment(const std::string &data)
Definition Request.cpp:412
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:374
Request & query(const std::string &key, const std::string &value)
Definition Request.cpp:233
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:301
void onSourceData(const char *chunk, std::size_t chunkLen) override
Definition Request.cpp:615
bool executeSendFragment(const char *chunk, std::size_t chunkLen)
Definition Request.cpp:559
const CiStringMap< std::string > & getQueries() const
Definition Request.cpp:642
const CiStringMap< std::string > & getCookies() const
Definition Request.cpp:650
Request & setTrailer(const std::string &field, const std::string &value, bool overwrite=true)
Definition Request.cpp:239
Request & cookie(const std::map< std::string, std::string > &cookies)
Definition Request.cpp:225
web::http::client::SocketContext * getSocketContext() const
Definition Request.cpp:654
static void responseParseError(const std::shared_ptr< Request > &request, const std::string &message)
Definition Request.cpp:258
void setMasterRequest(const std::shared_ptr< Request > &masterRequest)
Definition Request.cpp:113
std::function< void(const std::shared_ptr< Request > &request, const std::string &message)> onResponseParseError
Definition Request.h:187
CiStringMap< std::string > queries
Definition Request.h:171
Request & set(const std::map< std::string, std::string > &headers, bool overwrite=true)
Definition Request.cpp:205
std::size_t contentLength
Definition Request.h:181
web::http::client::SocketContext * socketContext
Definition Request.h:191
Request(web::http::client::SocketContext *socketContext, const std::string &host)
Definition Request.cpp:75
std::string hostFieldValue
Definition Request.h:164
Request & append(const std::string &field, const std::string &value)
Definition Request.cpp:147
Request & sendFragment(const char *chunk, std::size_t chunkLen)
Definition Request.cpp:402
std::list< RequestCommand * > requestCommands
Definition Request.h:177
void deliverResponse(const std::shared_ptr< Request > &request, const std::shared_ptr< Response > &response)
Definition Request.cpp:580
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:264
const CiStringMap< std::string > & getHeaders() const
Definition Request.cpp:646
Request & host(const std::string &hostFieldValue)
Definition Request.cpp:141
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:291
std::weak_ptr< Request > masterRequest
Definition Request.h:189
Request & type(const std::string &type)
Definition Request.cpp:213
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:416
void deliverResponseParseError(const std::shared_ptr< Request > &request, const std::string &message)
Definition Request.cpp:584
void upgrade(const std::shared_ptr< Response > &response, const std::function< void(const std::string &)> &status)
Definition Request.cpp:321
bool executeSendFile(const std::string &file, const std::function< void(int)> &onStatus)
Definition Request.cpp:461
bool executeUpgrade(const std::string &url, const std::string &protocols)
Definition Request.cpp:503
void onSourceConnect(core::pipe::Source *source) override
Definition Request.cpp:605
const std::string & get(const std::string &key, int i=0) const
Definition Response.cpp:53
SocketContextUpgradeFactory * select(Request &req, Response &res) override
SocketContextUpgradeFactory * load(const std::string &socketContextUpgradeName) override
SocketContextUpgradeFactory * select(const std::string &protocols, Request &req)
virtual void prepare(Request &request)=0
static void link(const std::string &upgradeContextName, SocketContextUpgradeFactory *(*linkedPlugin)())
void requestPrepared(Request &&request)
void requestDelivered(Request &&request, bool success)
SendFileCommand(const std::string &file, const std::function< void(int)> &onStatus)
SendFragmentCommand(const char *chunk, std::size_t chunkLen)
UpgradeCommand(const std::string &url, const std::string &protocols)
std::string to_http_date(struct tm *tm)
std::string url_encode(const std::string &text)
std::string file_mod_http_date(const std::string &filePath)
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