SNode.C
Loading...
Searching...
No Matches
Request.cpp
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#include "web/http/client/Request.h"
43
44#include "core/file/FileReader.h"
45#include "core/socket/stream/SocketConnection.h"
46#include "web/http/MimeTypes.h"
47#include "web/http/client/SocketContext.h"
48#include "web/http/client/SocketContextUpgradeFactorySelector.h"
49
50//
51
52#include "commands/EndCommand.h"
53#include "commands/SendFileCommand.h"
54#include "commands/SendFragmentCommand.h"
55#include "commands/SendHeaderCommand.h"
56#include "commands/UpgradeCommand.h"
57
58#ifndef DOXYGEN_SHOULD_SKIP_THIS
59
60#include "log/Logger.h"
61#include "web/http/http_utils.h"
62
63#include <cerrno>
64#include <filesystem>
65#include <sstream>
66#include <system_error>
67#include <utility>
68
69#endif /* DOXYGEN_SHOULD_SKIP_THIS */
70
71#define to_hex_str(int_val) (static_cast<std::ostringstream const&>(std::ostringstream() << std::uppercase << std::hex << int_val)).str()
72
73namespace web::http::client {
74
75 Request::Request(web::http::client::SocketContext* socketContext, const std::string& host)
76 : hostFieldValue(host)
77 , socketContext(socketContext) {
79 }
80
81 Request::Request(Request&& request) noexcept
82 : hostFieldValue(request.hostFieldValue) // NOLINT
83 , method(std::move(request.method))
84 , url(std::move(request.url))
85 , httpMajor(request.httpMajor)
86 , httpMinor(request.httpMinor)
87 , queries(std::move(request.queries))
88 , headers(std::move(request.headers))
89 , cookies(std::move(request.cookies))
90 , trailer(std::move(request.trailer))
91 , requestCommands(std::move(request.requestCommands))
96 , onResponseReceived(std::move(request.onResponseReceived))
98 , masterRequest(request.masterRequest) // NOLINT
100 request.init();
101 }
102
104 for (const RequestCommand* requestCommand : requestCommands) {
105 delete requestCommand;
106 }
107
108 if (!masterRequest.expired() && Sink::isStreaming()) {
110 }
111 }
112
113 void Request::setMasterRequest(const std::shared_ptr<Request>& masterRequest) {
114 this->masterRequest = masterRequest;
115 }
116
117 void Request::init() {
118 method = "GET";
119 url = "/";
120 httpMajor = 1;
121 httpMinor = 1;
122 queries.clear();
123 headers.clear();
124 cookies.clear();
125 trailer.clear();
126 for (const RequestCommand* requestCommand : requestCommands) {
127 delete requestCommand;
128 }
129 requestCommands.clear();
131 contentLength = 0;
134 onResponseReceived = nullptr;
135 onResponseParseError = nullptr;
136
138 set("X-Powered-By", "snode.c");
139 }
140
141 Request& Request::host(const std::string& hostFieldValue) {
142 set("Host", hostFieldValue);
143
144 return *this;
145 }
146
147 Request& Request::append(const std::string& field, const std::string& value) {
148 const std::map<std::string, std::string>::iterator it = headers.find(field);
149
150 if (it != headers.end()) {
151 set(field, it->second.append(", ").append(value));
152 } else {
153 set(field, value);
154 }
155
156 return *this;
157 }
158
159 Request& Request::set(const std::string& field, const std::string& value, bool overwrite) {
160 if (!value.empty()) {
161 if (overwrite) {
162 headers.insert_or_assign(field, value);
163 } else {
164 headers.insert({field, value});
165 }
166
167 if (web::http::ciEquals(field, "Connection")) {
168 if (web::http::ciContains(headers[field], "close")) {
170 } else if (web::http::ciContains(headers[field], "keep-alive")) {
172 }
173 } else if (web::http::ciEquals(field, "Content-Length")) {
174 contentLength = std::stoul(value);
176 headers.erase("Transfer-Encoding");
177 } else if (web::http::ciEquals(field, "Transfer-Encoding")) {
178 if (web::http::ciContains(headers[field], "chunked")) {
180 headers.erase("Content-Length");
181 }
182 if (web::http::ciContains(headers[field], "compressed")) {
183 }
184 if (web::http::ciContains(headers[field], "deflate")) {
185 }
186 if (web::http::ciContains(headers[field], "gzip")) {
187 }
188 } else if (web::http::ciEquals(field, "Content-Encoding")) {
189 if (web::http::ciContains(headers[field], "compressed")) {
190 }
191 if (web::http::ciContains(headers[field], "deflate")) {
192 }
193 if (web::http::ciContains(headers[field], "gzip")) {
194 }
195 if (web::http::ciContains(headers[field], "br")) {
196 }
197 }
198 } else {
199 headers.erase(field);
200 }
201
202 return *this;
203 }
204
205 Request& Request::set(const std::map<std::string, std::string>& headers, bool overwrite) {
206 for (const auto& [field, value] : headers) {
207 set(field, value, overwrite);
208 }
209
210 return *this;
211 }
212
213 Request& Request::type(const std::string& type) {
214 headers.insert({"Content-Type", type});
215
216 return *this;
217 }
218
219 Request& Request::cookie(const std::string& name, const std::string& value) {
220 cookies.insert({name, value});
221
222 return *this;
223 }
224
225 Request& Request::cookie(const std::map<std::string, std::string>& cookies) {
226 for (const auto& [name, value] : cookies) {
227 cookie(name, value);
228 }
229
230 return *this;
231 }
232
233 Request& Request::query(const std::string& key, const std::string& value) {
234 queries.insert({key, value});
235
236 return *this;
237 }
238
239 Request& Request::setTrailer(const std::string& field, const std::string& value, bool overwrite) {
240 if (!value.empty()) {
241 if (overwrite) {
242 trailer.insert_or_assign(field, value);
243 } else {
244 trailer.insert({field, value});
245 }
246 if (!headers.contains("Trailer")) {
247 set("Trailer", field);
248 } else {
249 headers["Trailer"].append("," + field);
250 }
251 } else {
252 trailer.erase(field);
253 }
254
255 return *this;
256 }
257
258 void Request::responseParseError(const std::shared_ptr<Request>& request, const std::string& message) {
260 << " HTTP: Response parse error: " << request->method << " " << request->url << " "
261 << "HTTP/" << request->httpMajor << "." << request->httpMinor << ": " << message;
262 }
263
264 bool Request::send(const char* chunk,
265 std::size_t chunkLen,
266 const std::function<void(const std::shared_ptr<Request>&, const std::shared_ptr<Response>&)>& onResponseReceived,
267 const std::function<void(const std::shared_ptr<Request>&, const std::string&)>& onResponseParseError) {
268 bool queued = true;
269
270 if (!masterRequest.expired()) {
271 this->onResponseReceived = onResponseReceived;
272 this->onResponseParseError = onResponseParseError;
273
274 if (chunkLen > 0) {
275 set("Content-Type", "application/octet-stream", false);
276 }
277
279 sendFragment(chunk, chunkLen);
280
281 requestCommands.push_back(new commands::EndCommand());
282
284 } else {
285 queued = false;
286 }
287
288 return queued;
289 }
290
291 bool Request::send(const std::string& chunk,
292 const std::function<void(const std::shared_ptr<Request>&, const std::shared_ptr<Response>&)>& onResponseReceived,
293 const std::function<void(const std::shared_ptr<Request>&, const std::string&)>& onResponseParseError) {
294 if (!chunk.empty()) {
295 set("Content-Type", "text/html; charset=utf-8", false);
296 }
297
298 return send(chunk.data(), chunk.size(), onResponseReceived, onResponseParseError);
299 }
300
301 bool Request::upgrade(const std::string& url,
302 const std::string& protocols,
303 const std::function<void(const std::shared_ptr<Request>&, const std::shared_ptr<Response>&)>& onResponseReceived,
304 const std::function<void(const std::shared_ptr<Request>&, const std::string&)>& onResponseParseError) {
305 bool success = true;
306
307 if (!masterRequest.expired()) {
308 this->onResponseReceived = onResponseReceived;
309 this->onResponseParseError = onResponseParseError;
310
311 requestCommands.push_back(new commands::UpgradeCommand(url, protocols));
312
314 } else {
315 success = false;
316 }
317
318 return success;
319 }
320
321 void Request::upgrade(const std::shared_ptr<Response>& response, const std::function<void(const std::string&)>& status) {
322 std::string name;
323
324 if (!masterRequest.expired()) {
325 if (response != nullptr) {
326 if (web::http::ciContains(response->get("connection"), "Upgrade")) {
327 web::http::client::SocketContextUpgradeFactory* socketContextUpgradeFactory =
329
330 if (socketContextUpgradeFactory != nullptr) {
331 name = socketContextUpgradeFactory->name();
332
334 << " HTTP upgrade: SocketContextUpgradeFactory created successful: " << name;
335
336 core::socket::stream::SocketContext* socketContextUpgrade =
337 socketContextUpgradeFactory->create(socketContext->getSocketConnection());
338
339 if (socketContextUpgrade != nullptr) {
341 << " HTTP upgrade: SocketContextUpgrade created successful: " << name;
342
343 socketContext->switchSocketContext(socketContextUpgrade);
344 } else {
346 << " HTTP upgrade: Create SocketContextUpgrade failed: " << name;
347
349 }
350 } else {
352 << " HTTP upgrade: SocketContextUpgradeFactory not supported by server: " << header("upgrade");
353
355 }
356 } else {
358 << " HTTP upgrade: Not any protocol supported by server: " << header("upgrade");
359
361 }
362 } else {
363 LOG(ERROR) << socketContext->getSocketConnection()->getConnectionName() << " HTTP upgrade: Response has gone away";
364
366 }
367 } else {
368 LOG(ERROR) << socketContext->getSocketConnection()->getConnectionName() << " HTTP upgrade: SocketContext has gone away";
369 }
370
371 status(name);
372 }
373
374 bool Request::sendFile(const std::string& file,
375 const std::function<void(int)>& onStatus,
376 const std::function<void(const std::shared_ptr<Request>&, const std::shared_ptr<Response>&)>& onResponseReceived,
377 const std::function<void(const std::shared_ptr<Request>&, const std::string&)>& onResponseParseError) {
378 bool queued = true;
379
380 if (!masterRequest.expired()) {
381 this->onResponseReceived = onResponseReceived;
382 this->onResponseParseError = onResponseParseError;
383
384 requestCommands.push_back(new commands::SendFileCommand(file, onStatus));
385
387 } else {
388 queued = false;
389 }
390
391 return queued;
392 }
393
395 if (!masterRequest.expired()) {
397 }
398
399 return *this;
400 }
401
402 Request& Request::sendFragment(const char* chunk, std::size_t chunkLen) {
403 if (!masterRequest.expired()) {
404 contentLength += chunkLen;
405
406 requestCommands.push_back(new commands::SendFragmentCommand(chunk, chunkLen));
407 }
408
409 return *this;
410 }
411
412 Request& Request::sendFragment(const std::string& data) {
413 return sendFragment(data.data(), data.size());
414 }
415
416 bool Request::end(const std::function<void(const std::shared_ptr<Request>&, const std::shared_ptr<Response>&)>& onResponseReceived,
417 const std::function<void(const std::shared_ptr<Request>&, const std::string&)>& onResponseParseError) {
418 bool queued = true;
419
420 if (!masterRequest.expired()) {
421 this->onResponseReceived = onResponseReceived;
422 this->onResponseParseError = onResponseParseError;
423
425
426 requestCommands.push_back(new commands::EndCommand());
427
429 } else {
430 queued = false;
431 }
432
433 return queued;
434 }
435
437 bool error = false;
438 bool atomar = true;
439
440 for (RequestCommand* requestCommand : requestCommands) {
441 if (!error) {
442 const bool atomarCommand = requestCommand->execute(this);
443 if (atomar) {
444 atomar = atomarCommand;
445 }
446
447 error = requestCommand->getError();
448 }
449
450 delete requestCommand;
451 }
452 requestCommands.clear();
453
454 if (atomar && (!error || contentLengthSent != 0)) {
456 }
457
458 return !error || contentLengthSent != 0;
459 }
460
461 bool Request::executeSendFile(const std::string& file, const std::function<void(int)>& onStatus) {
462 bool atomar = true;
463
464 std::string absolutFileName = file;
465
466 if (std::filesystem::exists(absolutFileName)) {
467 std::error_code ec;
468 absolutFileName = std::filesystem::canonical(absolutFileName);
469
470 if (std::filesystem::is_regular_file(absolutFileName, ec) && !ec) {
471 core::file::FileReader::open(absolutFileName)->pipe(this, [this, &atomar, &absolutFileName, &onStatus](int errnum) {
472 errno = errnum;
473 onStatus(errnum);
474
475 if (errnum == 0) {
476 if (httpMajor == 1) {
477 atomar = false;
478
479 set("Content-Type", web::http::MimeTypes::contentType(absolutFileName), false);
480 set("Last-Modified", httputils::file_mod_http_date(absolutFileName), false);
481 if (httpMinor == 1 && contentLength == 0) {
482 set("Transfer-Encoding", "chunked");
483 } else {
484 set("Content-Length", std::to_string(std::filesystem::file_size(absolutFileName) + contentLength));
485 }
486
488 }
489 }
490 });
491 } else {
492 errno = EINVAL;
493 onStatus(errno);
494 }
495 } else {
496 errno = ENOENT;
497 onStatus(errno);
498 }
499
500 return atomar;
501 }
502
503 bool Request::executeUpgrade(const std::string& url, const std::string& protocols) {
504 this->url = url;
505
506 set("Connection", "Upgrade", true);
507 set("Upgrade", protocols, true);
508
509 web::http::client::SocketContextUpgradeFactory* socketContextUpgradeFactory =
511
512 if (socketContextUpgradeFactory != nullptr) {
513 socketContextUpgradeFactory->checkRefCount();
514
516 } else {
518 }
519
520 return true;
521 }
522
523 bool Request::executeEnd() { // NOLINT
524 return true;
525 }
526
528 const std::string httpVersion = "HTTP/" + std::to_string(httpMajor) + "." + std::to_string(httpMinor);
529
530 std::string queryString;
531 if (!queries.empty()) {
532 queryString += "?";
533 for (auto& [key, value] : queries) {
534 queryString += httputils::url_encode(key) + "=" + httputils::url_encode(value) + "&";
535 }
536 queryString.pop_back();
537 }
538
539 socketContext->sendToPeer(method + " " + url + queryString + " " + httpVersion + "\r\n");
541
542 if (!headers.contains("Transfer-Encoding") && contentLength > 0) {
543 set("Content-Length", std::to_string(contentLength));
544 }
545
546 for (const auto& [field, value] : headers) {
547 socketContext->sendToPeer(std::string(field).append(":").append(value).append("\r\n"));
548 }
549
550 for (const auto& [name, value] : cookies) {
551 socketContext->sendToPeer(std::string("Cookie:").append(name).append("=").append(value).append("\r\n"));
552 }
553
555
556 return true;
557 }
558
559 bool Request::executeSendFragment(const char* chunk, std::size_t chunkLen) {
561 socketContext->sendToPeer(to_hex_str(chunkLen).append("\r\n"));
562 }
563
564 socketContext->sendToPeer(chunk, chunkLen);
565 contentLengthSent += chunkLen;
566
569 contentLength += chunkLen;
570 }
571
572 return true;
573 }
574
576 socketContext->requestPrepared(std::move(*this));
577 init();
578 }
579
580 void Request::deliverResponse(const std::shared_ptr<Request>& request, const std::shared_ptr<Response>& response) {
581 onResponseReceived(request, response);
582 }
583
584 void Request::deliverResponseParseError(const std::shared_ptr<Request>& request, const std::string& message) {
585 onResponseParseError(request, message);
586 }
587
589 if (!masterRequest.expired()) {
591 executeSendFragment("", 0); // For transfer encoding chunked. Terminate the chunk sequence.
592
593 if (!trailer.empty()) {
594 for (auto& [field, value] : trailer) {
595 socketContext->sendToPeer(std::string(field).append(":").append(value).append("\r\n"));
596 }
598 }
599 }
600
602 }
603 }
604
605 void Request::onSourceConnect(core::pipe::Source* source) {
606 if (!masterRequest.expired()) {
608 source->start();
609 }
610 } else {
611 source->stop();
612 }
613 }
614
615 void Request::onSourceData(const char* chunk, std::size_t chunkLen) {
616 executeSendFragment(chunk, chunkLen);
617 }
618
620 if (!masterRequest.expired()) {
622
624 }
625 }
626
627 void Request::onSourceError(int errnum) {
628 errno = errnum;
629
630 if (!masterRequest.expired()) {
633
635 }
636 }
637
638 std::string Request::header(const std::string& field) {
639 return headers.contains(field) ? headers[field] : "";
640 }
641
642 const web::http::CiStringMap<std::string>& Request::getQueries() const {
643 return queries;
644 }
645
646 const web::http::CiStringMap<std::string>& Request::getHeaders() const {
647 return headers;
648 }
649
650 const web::http::CiStringMap<std::string>& Request::getCookies() const {
651 return cookies;
652 }
653
655 return socketContext;
656 }
657
658} // namespace web::http::client
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)
core::socket::stream::SocketContext * create(core::socket::stream::SocketConnection *socketConnection) final
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 * select(const std::string &protocols, Request &req)
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