@@ -220,6 +220,7 @@ void connection<config>::ping(std::string const& payload, lib::error_code& ec) {
220220 ec = lib::error_code ();
221221}
222222
223+ #ifndef _WEBSOCKETPP_NO_EXCEPTIONS_
223224template <typename config>
224225void connection<config>::ping(std::string const & payload) {
225226 lib::error_code ec;
@@ -228,6 +229,7 @@ void connection<config>::ping(std::string const & payload) {
228229 throw exception (ec);
229230 }
230231}
232+ #endif // _WEBSOCKETPP_NO_EXCEPTIONS_
231233
232234template <typename config>
233235void connection<config>::handle_pong_timeout(std::string payload,
@@ -291,6 +293,7 @@ void connection<config>::pong(std::string const& payload, lib::error_code& ec) {
291293 ec = lib::error_code ();
292294}
293295
296+ #ifndef _WEBSOCKETPP_NO_EXCEPTIONS_
294297template <typename config>
295298void connection<config>::pong(std::string const & payload) {
296299 lib::error_code ec;
@@ -299,6 +302,7 @@ void connection<config>::pong(std::string const & payload) {
299302 throw exception (ec);
300303 }
301304}
305+ #endif // _WEBSOCKETPP_NO_EXCEPTIONS_
302306
303307template <typename config>
304308void connection<config>::close(close::status::value const code,
@@ -322,6 +326,7 @@ void connection<config>::close(close::status::value const code,
322326 ec = this ->send_close_frame (code,tr,false ,close::status::terminal (code));
323327}
324328
329+ #ifndef _WEBSOCKETPP_NO_EXCEPTIONS_
325330template <typename config>
326331void connection<config>::close(close::status::value const code,
327332 std::string const & reason)
@@ -332,6 +337,7 @@ void connection<config>::close(close::status::value const code,
332337 throw exception (ec);
333338 }
334339}
340+ #endif // _WEBSOCKETPP_NO_EXCEPTIONS_
335341
336342// / Trigger the on_interrupt handler
337343/* *
@@ -474,6 +480,7 @@ void connection<config>::add_subprotocol(std::string const & value,
474480 m_requested_subprotocols.push_back (value);
475481}
476482
483+ #ifndef _WEBSOCKETPP_NO_EXCEPTIONS_
477484template <typename config>
478485void connection<config>::add_subprotocol(std::string const & value) {
479486 lib::error_code ec;
@@ -482,6 +489,7 @@ void connection<config>::add_subprotocol(std::string const & value) {
482489 throw exception (ec);
483490 }
484491}
492+ #endif // _WEBSOCKETPP_NO_EXCEPTIONS_
485493
486494
487495template <typename config>
@@ -513,6 +521,7 @@ void connection<config>::select_subprotocol(std::string const & value,
513521 ec = lib::error_code ();
514522}
515523
524+ #ifndef _WEBSOCKETPP_NO_EXCEPTIONS_
516525template <typename config>
517526void connection<config>::select_subprotocol(std::string const & value) {
518527 lib::error_code ec;
@@ -521,6 +530,7 @@ void connection<config>::select_subprotocol(std::string const & value) {
521530 throw exception (ec);
522531 }
523532}
533+ #endif // _WEBSOCKETPP_NO_EXCEPTIONS_
524534
525535
526536template <typename config>
@@ -549,10 +559,10 @@ void connection<config>::set_status(http::status_code::value code,
549559 ec = error::make_error_code (error::invalid_state);
550560 return ;
551561 }
552- m_response.set_status (code);
553- ec = lib::error_code ();
562+ ec = m_response.set_status (code);
554563}
555564
565+ #ifndef _WEBSOCKETPP_NO_EXCEPTIONS_
556566template <typename config>
557567void connection<config>::set_status(http::status_code::value code)
558568{
@@ -562,6 +572,7 @@ void connection<config>::set_status(http::status_code::value code)
562572 throw exception (" Call to set_status from invalid state" , ec);
563573 }
564574}
575+ #endif // _WEBSOCKETPP_NO_EXCEPTIONS_
565576
566577template <typename config>
567578void connection<config>::set_status(http::status_code::value code,
@@ -572,10 +583,10 @@ void connection<config>::set_status(http::status_code::value code,
572583 return ;
573584 }
574585
575- m_response.set_status (code,msg);
576- ec = lib::error_code ();
586+ ec = m_response.set_status (code,msg);
577587}
578588
589+ #ifndef _WEBSOCKETPP_NO_EXCEPTIONS_
579590template <typename config>
580591void connection<config>::set_status(http::status_code::value code,
581592 std::string const & msg)
@@ -586,6 +597,7 @@ void connection<config>::set_status(http::status_code::value code,
586597 throw exception (" Call to set_status from invalid state" , ec);
587598 }
588599}
600+ #endif // _WEBSOCKETPP_NO_EXCEPTIONS_
589601
590602template <typename config>
591603void connection<config>::set_body(std::string const & value,
@@ -599,14 +611,41 @@ void connection<config>::set_body(std::string const & value,
599611 ec = m_response.set_body (value);
600612}
601613
614+ #ifndef _WEBSOCKETPP_NO_EXCEPTIONS_
602615template <typename config>
603616void connection<config>::set_body(std::string const & value) {
604617 lib::error_code ec;
605618 this ->set_body (value, ec);
606619 if (ec) {
607- throw exception (" Call to set_status from invalid state" , ec);
620+ throw exception (" Call to set_body from invalid state" , ec);
621+ }
622+ }
623+ #endif // _WEBSOCKETPP_NO_EXCEPTIONS_
624+
625+ #ifdef _WEBSOCKETPP_MOVE_SEMANTICS_
626+ template <typename config>
627+ void connection<config>::set_body(std::string && value,
628+ lib::error_code & ec)
629+ {
630+ if (m_internal_state != istate::PROCESS_HTTP_REQUEST) {
631+ ec = error::make_error_code (error::invalid_state);
632+ return ;
633+ }
634+
635+ ec = m_response.set_body (std::move (value));
636+ }
637+
638+ #ifndef _WEBSOCKETPP_NO_EXCEPTIONS_
639+ template <typename config>
640+ void connection<config>::set_body(std::string && value) {
641+ lib::error_code ec;
642+ this ->set_body (std::move (value), ec);
643+ if (ec) {
644+ throw exception (" Call to set_body from invalid state" , ec);
608645 }
609646}
647+ #endif // _WEBSOCKETPP_NO_EXCEPTIONS_
648+ #endif // _WEBSOCKETPP_MOVE_SEMANTICS_
610649
611650template <typename config>
612651void connection<config>::append_header(std::string const & key,
@@ -629,6 +668,7 @@ void connection<config>::append_header(std::string const & key,
629668 }
630669}
631670
671+ #ifndef _WEBSOCKETPP_NO_EXCEPTIONS_
632672template <typename config>
633673void connection<config>::append_header(std::string const & key,
634674 std::string const & val)
@@ -639,6 +679,7 @@ void connection<config>::append_header(std::string const & key,
639679 throw exception (" Call to append_header from invalid state" , ec);
640680 }
641681}
682+ #endif // _WEBSOCKETPP_NO_EXCEPTIONS_
642683
643684template <typename config>
644685void connection<config>::replace_header(std::string const & key,
@@ -661,6 +702,7 @@ void connection<config>::replace_header(std::string const & key,
661702 }
662703}
663704
705+ #ifndef _WEBSOCKETPP_NO_EXCEPTIONS_
664706template <typename config>
665707void connection<config>::replace_header(std::string const & key,
666708 std::string const & val)
@@ -671,6 +713,7 @@ void connection<config>::replace_header(std::string const & key,
671713 throw exception (" Call to replace_header from invalid state" , ec);
672714 }
673715}
716+ #endif // _WEBSOCKETPP_NO_EXCEPTIONS_
674717
675718template <typename config>
676719void connection<config>::remove_header(std::string const & key,
@@ -693,6 +736,7 @@ void connection<config>::remove_header(std::string const & key,
693736 }
694737}
695738
739+ #ifndef _WEBSOCKETPP_NO_EXCEPTIONS_
696740template <typename config>
697741void connection<config>::remove_header(std::string const & key)
698742{
@@ -702,6 +746,7 @@ void connection<config>::remove_header(std::string const & key)
702746 throw exception (" Call to remove_header from invalid state" , ec);
703747 }
704748}
749+ #endif // _WEBSOCKETPP_NO_EXCEPTIONS_
705750
706751// / Defer HTTP Response until later
707752/* *
@@ -755,6 +800,7 @@ void connection<config>::send_http_response(lib::error_code & ec) {
755800 ec = lib::error_code ();
756801}
757802
803+ #ifndef _WEBSOCKETPP_NO_EXCEPTIONS_
758804template <typename config>
759805void connection<config>::send_http_response() {
760806 lib::error_code ec;
@@ -763,6 +809,7 @@ void connection<config>::send_http_response() {
763809 throw exception (ec);
764810 }
765811}
812+ #endif // _WEBSOCKETPP_NO_EXCEPTIONS_
766813
767814
768815
@@ -1265,7 +1312,7 @@ lib::error_code connection<config>::process_handshake_request() {
12651312 return error::make_error_code (error::http_connection_ended);
12661313 }
12671314 } else {
1268- set_status (http::status_code::upgrade_required);
1315+ m_response. set_status (http::status_code::upgrade_required);
12691316 return error::make_error_code (error::upgrade_required);
12701317 }
12711318
@@ -1370,6 +1417,7 @@ void connection<config>::write_http_response(lib::error_code const & ec) {
13701417 }
13711418
13721419 if (m_response.get_status_code () == http::status_code::uninitialized) {
1420+ lib::error_code status_ec;
13731421 m_response.set_status (http::status_code::internal_server_error);
13741422 m_ec = error::make_error_code (error::general);
13751423 } else {
@@ -1865,13 +1913,18 @@ void connection<config>::handle_terminate(terminate_status tstat,
18651913 // call the termination handler if it exists
18661914 // if it exists it might (but shouldn't) refer to a bad memory location.
18671915 // If it does, we don't care and should catch and ignore it.
1916+ // todo: there has to be a better way to do this.
18681917 if (m_termination_handler) {
1918+ #ifndef _WEBSOCKETPP_NO_EXCEPTIONS_
18691919 try {
18701920 m_termination_handler (type::get_shared ());
18711921 } catch (std::exception const & e) {
18721922 m_elog->write (log::elevel::warn,
18731923 std::string (" termination_handler call failed. Reason was: " )+e.what ());
18741924 }
1925+ #else
1926+ m_termination_handler (type::get_shared ());
1927+ #endif
18751928 }
18761929}
18771930
0 commit comments