1#include "MultithreadedWebServer.h"
4#include "HTTPSNetwork.h"
6#include "Exceptions/NotImplementedException.h"
7#include "Exceptions/FileDoesNotExistException.h"
8#include "Exceptions/NotFoundException.h"
9#include "Exceptions/CantFindFunctionException.h"
10#include "Exceptions/MissingLoadTypeException.h"
11#include "Exceptions/CantLoadSourceException.h"
12#include "Exceptions/BadRequestException.h"
13#include "Utility/RouteParameters.h"
14#include "Exceptions/SSLException.h"
15#include "Utility/Singletons/HTTPSSingleton.h"
18#pragma warning(disable: 6387)
25 void MultithreadedWebServer::clientConnection(
const string& ip, SOCKET clientSocket, sockaddr addr, function<
void()>& cleanup)
33 ssl = SSL_new(context);
37 throw web::exceptions::SSLException(__LINE__, __FILE__);
40 if (!SSL_set_fd(ssl,
static_cast<int>(clientSocket)))
44 throw web::exceptions::SSLException(__LINE__, __FILE__);
47 if (
int errorCode = SSL_accept(ssl); errorCode != 1)
49 throw web::exceptions::SSLException(__LINE__, __FILE__, ssl, errorCode);
53 catch (
const web::exceptions::SSLException& e)
57 Log::error(
"SSL exception: {}, ip: {}",
"LogHTTPS", e.what(), ip);
63 streams::IOSocketStream stream
66 make_unique<web::HTTPSNetwork>(clientSocket, ssl, context) :
67 make_unique<web::HTTPNetwork>(clientSocket)
69 unordered_map<string, unique_ptr<BaseExecutor>> statefulExecutors;
70 HTTPResponse response;
76 HTTPRequest request(sessionsManager, *
this, *resources, *resources, databaseManager, addr, stream);
78 response.setDefault();
87 executorsManager.service(request, response, statefulExecutors);
99 catch (
const web::exceptions::WebException& e)
103 Log::error(
"Multithreaded serve exception: {}",
"Multithreaded", e.what());
108 catch (
const exceptions::BadRequestException& e)
110 resources->badRequestError(response, &e);
114 catch (
const file_manager::exceptions::FileDoesNotExistException& e)
116 resources->notFoundError(response, &e);
120 catch (
const exceptions::NotFoundException& e)
122 resources->notFoundError(response, &e);
126 catch (
const exceptions::BaseExecutorException& e)
128 resources->internalServerError(response, &e);
132 catch (
const exception& e)
134 resources->internalServerError(response, &e);
140 resources->internalServerError(response,
nullptr);
147 MultithreadedWebServer::MultithreadedWebServer
149 const json::JSONParser& configuration,
150 const vector<utility::JSONSettingsParser>& parsers,
151 const filesystem::path& assets,
152 const filesystem::path& pathToTemplates,
153 uint64_t cachingSize,
157 const vector<string>& pathToSources
168 IExecutorFunctionality