@@ -187,6 +187,24 @@ class file_response_resource : public http_resource
187187 }
188188};
189189
190+ class exception_resource : public http_resource
191+ {
192+ public:
193+ const http_response render_GET (const http_request& req)
194+ {
195+ throw std::domain_error (" invalid" );
196+ }
197+ };
198+
199+ class error_resource : public http_resource
200+ {
201+ public:
202+ const http_response render_GET (const http_request& req)
203+ {
204+ throw " invalid" ;
205+ }
206+ };
207+
190208LT_BEGIN_SUITE (basic_suite)
191209
192210 webserver* ws;
@@ -724,6 +742,52 @@ LT_BEGIN_AUTO_TEST(basic_suite, file_serving_resource)
724742 curl_easy_cleanup (curl);
725743LT_END_AUTO_TEST (file_serving_resource)
726744
745+ LT_BEGIN_AUTO_TEST(basic_suite, exception_forces_500)
746+ exception_resource* resource = new exception_resource();
747+ ws->register_resource (" base" , resource);
748+ curl_global_init (CURL_GLOBAL_ALL);
749+
750+ std::string s;
751+ CURL *curl = curl_easy_init();
752+ CURLcode res;
753+ curl_easy_setopt (curl, CURLOPT_URL, " localhost:8080/base" );
754+ curl_easy_setopt (curl, CURLOPT_HTTPGET, 1L );
755+ curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, writefunc);
756+ curl_easy_setopt (curl, CURLOPT_WRITEDATA, &s);
757+ res = curl_easy_perform(curl);
758+ LT_ASSERT_EQ (res, 0 );
759+ LT_CHECK_EQ (s, " Internal Error" );
760+
761+ long http_code = 0 ;
762+ curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &http_code);
763+ LT_ASSERT_EQ (http_code, 500 );
764+
765+ curl_easy_cleanup (curl);
766+ LT_END_AUTO_TEST (exception_forces_500)
767+
768+ LT_BEGIN_AUTO_TEST(basic_suite, untyped_error_forces_500)
769+ error_resource* resource = new error_resource();
770+ ws->register_resource (" base" , resource);
771+ curl_global_init (CURL_GLOBAL_ALL);
772+
773+ std::string s;
774+ CURL *curl = curl_easy_init();
775+ CURLcode res;
776+ curl_easy_setopt (curl, CURLOPT_URL, " localhost:8080/base" );
777+ curl_easy_setopt (curl, CURLOPT_HTTPGET, 1L );
778+ curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, writefunc);
779+ curl_easy_setopt (curl, CURLOPT_WRITEDATA, &s);
780+ res = curl_easy_perform(curl);
781+ LT_ASSERT_EQ (res, 0 );
782+ LT_CHECK_EQ (s, " Internal Error" );
783+
784+ long http_code = 0 ;
785+ curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &http_code);
786+ LT_ASSERT_EQ (http_code, 500 );
787+
788+ curl_easy_cleanup (curl);
789+ LT_END_AUTO_TEST (untyped_error_forces_500)
790+
727791LT_BEGIN_AUTO_TEST_ENV()
728792 AUTORUN_TESTS()
729793LT_END_AUTO_TEST_ENV()
0 commit comments