Skip to content

Commit 65ce5d1

Browse files
committed
Added test for no response use case
1 parent 852c437 commit 65ce5d1

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

src/http_response.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ http_response::http_response(const http_response_builder& builder):
6969

7070
http_response::~http_response()
7171
{
72-
if(ce != 0x0)
73-
webserver::unlock_cache_entry(ce);
72+
if(ce != 0x0) webserver::unlock_cache_entry(ce);
7473
}
7574

7675
//RESPONSE

src/httpserver/http_response.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,14 @@ class http_response
104104
{
105105
}
106106

107-
http_response(): response_code(-1)
107+
http_response():
108+
response_code(-1),
109+
fp(-1),
110+
underlying_connection(0x0),
111+
ce(0x0),
112+
completed(false),
113+
ws(0x0),
114+
connection_id(0x0)
108115
{
109116
}
110117

src/webserver.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,9 +646,14 @@ const http_response webserver::method_not_allowed_page(details::modded_request*
646646
const http_response webserver::internal_error_page(details::modded_request* mr, bool force_our) const
647647
{
648648
if(internal_error_resource != 0x0 && !force_our)
649+
{
649650
return internal_error_resource(*mr->dhr);
651+
}
650652
else
651-
return http_response_builder(GENERIC_ERROR, http_utils::http_internal_server_error).string_response();
653+
{
654+
http_response hr = http_response_builder(GENERIC_ERROR, http_utils::http_internal_server_error, "text/plain").string_response();
655+
return hr;
656+
}
652657
}
653658

654659
int webserver::bodyless_requests_answer(
@@ -872,7 +877,10 @@ int webserver::finalize_answer(
872877
if(hrm->is_allowed(method))
873878
{
874879
mr->dhrs = NEW_OR_MOVE(http_response, ((hrm)->*(mr->callback))(*mr->dhr)); //copy in memory (move in case)
875-
if (mr->dhrs->get_response_code() == -1) mr->dhrs = NEW_OR_MOVE(http_response, internal_error_page(mr));
880+
if (mr->dhrs->get_response_code() == -1)
881+
{
882+
mr->dhrs = NEW_OR_MOVE(http_response, internal_error_page(mr));
883+
}
876884
}
877885
else
878886
{

test/integ/basic.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ LT_BEGIN_SUITE(basic_suite)
157157
LT_END_SUITE(basic_suite)
158158

159159
LT_BEGIN_AUTO_TEST(basic_suite, two_endpoints)
160-
161160
ok_resource* ok = new ok_resource();
162161
ws->register_resource("OK", ok);
163162
nok_resource* nok = new nok_resource();
@@ -413,26 +412,21 @@ LT_BEGIN_AUTO_TEST(basic_suite, empty_arg)
413412
curl_easy_cleanup(curl);
414413
LT_END_AUTO_TEST(empty_arg)
415414

416-
/*
417415
LT_BEGIN_AUTO_TEST(basic_suite, no_response)
418416
no_response_resource* resource = new no_response_resource();
419417
ws->register_resource("base", resource);
420418
curl_global_init(CURL_GLOBAL_ALL);
421-
std::string s;
422-
CURL* curl;
423-
CURLcode res;
424419

425-
curl = curl_easy_init();
420+
CURL* curl = curl_easy_init();
426421
curl_easy_setopt(curl, CURLOPT_URL, "localhost:8080/base");
427422
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
428-
res = curl_easy_perform(curl);
423+
CURLcode res = curl_easy_perform(curl);
429424
LT_ASSERT_EQ(res, 0);
430425
long http_code = 0;
431426
curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &http_code);
432427
LT_ASSERT_EQ(http_code, 500);
433428
curl_easy_cleanup(curl);
434429
LT_END_AUTO_TEST(no_response)
435-
*/
436430

437431
LT_BEGIN_AUTO_TEST_ENV()
438432
AUTORUN_TESTS()

0 commit comments

Comments
 (0)