Skip to content

Commit f669f15

Browse files
author
Sebastiano Merlino
committed
Added parameter in http_response to specify if it needs to be deleted by
WS
1 parent 9fa3961 commit f669f15

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

src/http_response.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ shoutCAST_response::shoutCAST_response
7676
(
7777
const std::string& content,
7878
int response_code,
79-
const std::string& content_type
79+
const std::string& content_type,
80+
bool autodelete
8081
):
81-
http_response(http_response::SHOUTCAST_CONTENT, content, response_code | http_utils::shoutcast_response, content_type)
82+
http_response(http_response::SHOUTCAST_CONTENT, content, response_code | http_utils::shoutcast_response, content_type, autodelete)
8283
{
8384
}
8485

src/httpserver/http_response.hpp

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class http_response
7676
const std::string& content = "",
7777
int response_code = 200,
7878
const std::string& content_type = "text/plain",
79+
bool autodelete = true,
7980
const std::string& realm = "",
8081
const std::string& opaque = "",
8182
bool reload_nonce = false,
@@ -87,6 +88,7 @@ class http_response
8788
response_type(response_type),
8889
content(content),
8990
response_code(response_code),
91+
autodelete(autodelete),
9092
realm(realm),
9193
opaque(opaque),
9294
reload_nonce(reload_nonce),
@@ -107,6 +109,7 @@ class http_response
107109
response_type(b.response_type),
108110
content(b.content),
109111
response_code(b.response_code),
112+
autodelete(b.autodelete),
110113
realm(b.realm),
111114
opaque(b.opaque),
112115
reload_nonce(b.reload_nonce),
@@ -299,6 +302,7 @@ class http_response
299302
response_type_T response_type;
300303
std::string content;
301304
int response_code;
305+
bool autodelete;
302306
std::string realm;
303307
std::string opaque;
304308
bool reload_nonce;
@@ -325,8 +329,9 @@ class http_string_response : public http_response
325329
(
326330
const std::string& content,
327331
int response_code,
328-
const std::string& content_type = "text/plain"
329-
): http_response(http_response::STRING_CONTENT, content, response_code, content_type) { }
332+
const std::string& content_type = "text/plain",
333+
bool autodelete = true
334+
): http_response(http_response::STRING_CONTENT, content, response_code, content_type, autodelete) { }
330335

331336
http_string_response(const http_response& b) : http_response(b) { }
332337
};
@@ -339,8 +344,9 @@ class http_byte_response : public http_response
339344
const char* content,
340345
size_t content_length,
341346
int response_code,
342-
const std::string& content_type = "text/plain"
343-
): http_response(http_response::STRING_CONTENT, std::string(content, content_length), response_code, content_type) { }
347+
const std::string& content_type = "text/plain",
348+
bool autodelete = true
349+
): http_response(http_response::STRING_CONTENT, std::string(content, content_length), response_code, content_type, autodelete) { }
344350
};
345351

346352
class http_file_response : public http_response
@@ -350,8 +356,9 @@ class http_file_response : public http_response
350356
(
351357
const std::string& filename,
352358
int response_code,
353-
const std::string& content_type = "text/plain"
354-
) : http_response(http_response::FILE_CONTENT, filename, response_code, content_type)
359+
const std::string& content_type = "text/plain",
360+
bool autodelete = true
361+
) : http_response(http_response::FILE_CONTENT, filename, response_code, content_type, autodelete)
355362
{
356363
}
357364

@@ -368,9 +375,10 @@ class http_basic_auth_fail_response : public http_response
368375
const std::string& content,
369376
int response_code,
370377
const std::string& content_type = "text/plain",
378+
bool autodelete = true,
371379
const std::string& realm = "",
372380
const http_response::response_type_T& response_type = http_response::BASIC_AUTH_FAIL
373-
) : http_response(http_response::BASIC_AUTH_FAIL, content, response_code, content_type, realm) { }
381+
) : http_response(http_response::BASIC_AUTH_FAIL, content, response_code, content_type, autodelete, realm) { }
374382

375383
http_basic_auth_fail_response(const http_response& b) : http_response(b) { }
376384
};
@@ -383,10 +391,11 @@ class http_digest_auth_fail_response : public http_response
383391
const std::string& content,
384392
int response_code,
385393
const std::string& content_type = "text/plain",
394+
bool autodelete = true,
386395
const std::string& realm = "",
387396
const std::string& opaque = "",
388397
bool reload_nonce = false
389-
) : http_response(http_response::DIGEST_AUTH_FAIL, content, response_code, content_type, realm, opaque, reload_nonce)
398+
) : http_response(http_response::DIGEST_AUTH_FAIL, content, response_code, content_type, autodelete, realm, opaque, reload_nonce)
390399
{
391400
}
392401

@@ -400,7 +409,8 @@ class shoutCAST_response : public http_response
400409
(
401410
const std::string& content,
402411
int response_code,
403-
const std::string& content_type = "text/plain"
412+
const std::string& content_type = "text/plain",
413+
bool autodelete = true
404414
);
405415

406416
shoutCAST_response(const http_response& b) : http_response(b) { }
@@ -431,9 +441,10 @@ class long_polling_receive_response : public http_response
431441
int response_code,
432442
const std::string& content_type,
433443
const std::vector<std::string>& topics,
444+
bool autodelete = true,
434445
int keepalive_secs = -1,
435446
std::string keepalive_msg = ""
436-
) : http_response(http_response::LONG_POLLING_RECEIVE, content, response_code, content_type, "", "", false, topics, keepalive_secs, keepalive_msg)
447+
) : http_response(http_response::LONG_POLLING_RECEIVE, content, response_code, content_type, autodelete, "", "", false, topics, keepalive_secs, keepalive_msg)
437448
{
438449
}
439450

@@ -453,8 +464,9 @@ class long_polling_send_response : public http_response
453464
long_polling_send_response
454465
(
455466
const std::string& content,
456-
const std::string& topic
457-
) : http_response(http_response::LONG_POLLING_SEND, content, 200, "", "", "", false, std::vector<std::string>(), -1, "", topic)
467+
const std::string& topic,
468+
bool autodelete = true
469+
) : http_response(http_response::LONG_POLLING_SEND, content, 200, "", autodelete, "", "", false, std::vector<std::string>(), -1, "", topic)
458470
{
459471
}
460472

src/webserver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ void webserver::request_completed (void *cls, struct MHD_Connection *connection,
303303
}
304304
if(mr->second)
305305
delete mr->dhr; //TODO: verify. It could be an error
306-
if(mr->dhrs)
306+
if(mr->dhrs && mr->dhrs->autodelete)
307307
delete mr->dhrs;
308308
delete mr->complete_uri;
309309
free(mr);

0 commit comments

Comments
 (0)