Skip to content

Commit 283f73c

Browse files
committed
http_request: Remove uploaded files in destructor
If the user needs those files, she should copy/move theme in the request handler. References: etr#264 Signed-off-by: Alexander Dahl <ada@thorsis.com>
1 parent 31dfed7 commit 283f73c

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/http_request.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,13 @@ std::ostream &operator<< (std::ostream &os, const http_request &r) {
256256
return os;
257257
}
258258

259+
http_request::~http_request() {
260+
for ( const auto &file_key : this->get_files() ) {
261+
for ( const auto &files : file_key.second ) {
262+
// C++17 has std::filesystem::remove()
263+
remove(files.second.get_file_system_file_name().c_str());
264+
}
265+
}
266+
}
267+
259268
} // namespace httpserver

src/httpserver/http_request.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ struct MHD_Connection;
4646

4747
namespace httpserver {
4848

49+
namespace details { struct modded_request; }
50+
4951
/**
5052
* Class representing an abstraction for an Http Request. It is used from classes using these apis to receive information through http protocol.
5153
**/
@@ -254,6 +256,8 @@ class http_request {
254256
http_request& operator=(const http_request& b) = default;
255257
http_request& operator=(http_request&& b) = default;
256258

259+
~http_request();
260+
257261
std::string path;
258262
std::string method;
259263
std::map<std::string, std::string, http::arg_comparator> args;
@@ -356,6 +360,7 @@ class http_request {
356360
const std::map<std::string, std::string, http::header_comparator> get_headerlike_values(enum MHD_ValueKind kind) const;
357361

358362
friend class webserver;
363+
friend struct details::modded_request;
359364
};
360365

361366
std::ostream &operator<< (std::ostream &os, const http_request &r);

0 commit comments

Comments
 (0)