28 const web::BaseTCPServer& serverReference;
29 streams::IOSocketStream& stream;
31 std::unordered_map<std::string, std::variant<std::string, int64_t, double>> routeParameters;
33 web::HTTPParser parser;
38 static bool isWebFrameworkDynamicPages(
const std::string& filePath);
41 static web::HTTPParser sendRequestToAnotherServer(std::string_view ip, std::string_view port, std::string_view request, DWORD timeout = 30'000,
bool useHTTPS =
false);
58 const std::string& getRawParameters()
const;
64 const std::string& getMethod()
const;
70 const std::unordered_map<std::string, std::string>& getKeyValueParameters()
const;
76 std::string getHTTPVersion()
const;
82 const web::HeadersMap& getHeaders()
const;
88 const std::string& getBody()
const;
95 void setAttribute(
const std::string& name,
const std::string& value);
103 std::string getAttribute(
const std::string& name);
108 void deleteSession();
114 void deleteAttribute(
const std::string& name);
120 web::HeadersMap getCookies()
const;
129 void sendAssetFile(
const std::string& filePath,
HTTPResponse& response,
const std::unordered_map<std::string, std::string>& variables = {},
bool isBinary =
true,
const std::string& fileName =
"");
137 void sendStaticFile(
const std::string& filePath,
HTTPResponse& response,
bool isBinary =
true,
const std::string& fileName =
"");
146 void sendDynamicFile(
const std::string& filePath,
HTTPResponse& response,
const std::unordered_map<std::string, std::string>& variables,
bool isBinary =
false,
const std::string& fileName =
"");
154 void streamFile(std::string_view filePath,
HTTPResponse& response, std::string_view fileName,
size_t chunkSize = defaultChunkSize);
159 void registerDynamicFunction(
const std::string& functionName, std::function<std::string(
const std::vector<std::string>&)>&& function);
163 void unregisterDynamicFunction(
const std::string& functionName);
168 bool isDynamicFunctionRegistered(
const std::string& functionName);
174 const json::JSONParser& getJSON()
const;
180 const std::vector<std::string>& getChunks()
const;
186 const web::HTTPParser& getParser()
const;
192 std::string getClientIpV4()
const;
198 std::string getServerIpV4()
const;
204 uint16_t getClientPort()
const;
210 uint16_t getServerPort()
const;
219 template<utility::concepts::RouteParameterType T>
229 template<std::derived_from<sqlite::SQLiteDatabaseModel> T,
typename... Args>
230 std::shared_ptr<T> createModel(Args&&... args);
237 template<std::derived_from<sqlite::SQLiteDatabaseModel> T>
238 std::shared_ptr<T> getModel()
const;
247 template<std::derived_from<utility::ChunkGenerator> T,
typename... Args>
248 void sendChunks(
HTTPResponse& response, Args&&... args);
258 template<std::derived_from<utility::ChunkGenerator> T,
typename... Args>
259 void sendFileChunks(
HTTPResponse& response, std::string_view fileName, Args&&... args);
268 friend streams::IOSocketStream& operator >> (streams::IOSocketStream& stream,
HTTPRequest& request);
276 friend std::ostream& operator << (std::ostream& stream,
const HTTPRequest& request);
321 T generator(std::forward<Args>(args)...);
323 web::HTTPBuilder builder = web::HTTPBuilder().chunk(generator.generate()).partialChunks().responseCode(web::responseCodes::ok).headers
326 "Server",
"WebFramework-Server",
327 "Connection",
"keep-alive"
334 "Content-Disposition", std::format(R
"(attachment; filename="{}")", fileName)
338 stream << builder.build();
340 response.setIsValid(false);
344 std::string data = generator.generate();
346 stream << web::HTTPBuilder::getChunk(data);
348 if (stream.eof() || data.empty())