Refactor deferred http handler support to better match the library conventions
This commit is contained in:
1 parent
c18f210ea3
commit
acb53a379c
5 files changed
+66
-11
No files matched your search
@@ -172,8 +172,8 @@ void defer_http_func(server* s, bool * deferred, websocketpp::connection_hdl hdl
|
||||
|
||||
server::connection_ptr con = s->get_con_from_hdl(hdl);
|
||||
|
||||
websocketpp::lib::error_code ec;
|
||||
con->defer_http_response(ec);
|
||||
websocketpp::lib::error_code ec = con->defer_http_response();
|
||||
BOOST_CHECK_EQUAL(ec, websocketpp::lib::error_code());
|
||||
}
|
||||
|
||||
void check_on_fail(server* s, websocketpp::lib::error_code ec, bool & called,
|
||||
@@ -262,7 +262,7 @@ BOOST_AUTO_TEST_CASE( deferred_http_request ) {
|
||||
con->set_status(websocketpp::http::status_code::ok);
|
||||
|
||||
websocketpp::lib::error_code ec;
|
||||
con->send_http_response(ec);
|
||||
s.send_http_response(con->get_handle(),ec);
|
||||
BOOST_CHECK_EQUAL(ec, websocketpp::lib::error_code());
|
||||
BOOST_CHECK_EQUAL(ostream.str(), output);
|
||||
con->send_http_response(ec);
|
||||
|
||||
@@ -1076,7 +1076,7 @@ public:
|
||||
return m_request;
|
||||
}
|
||||
|
||||
/// Defer HTTP Response until later
|
||||
/// Defer HTTP Response until later (Exception free)
|
||||
/**
|
||||
* Used in the http handler to defer the HTTP response for this connection
|
||||
* until later. Handshake timers will be canceled and the connection will be
|
||||
@@ -1087,11 +1087,11 @@ public:
|
||||
*
|
||||
* @since 0.6.0
|
||||
*
|
||||
* @param ec A status code, zero on success, non-zero otherwise
|
||||
* @return A status code, zero on success, non-zero otherwise
|
||||
*/
|
||||
void defer_http_response(lib::error_code & ec);
|
||||
lib::error_code defer_http_response();
|
||||
|
||||
/// Send deferred HTTP Response
|
||||
/// Send deferred HTTP Response (exception free)
|
||||
/**
|
||||
* Sends an http response to an HTTP connection that was deferred. This will
|
||||
* send a complete response including all headers, status line, and body
|
||||
@@ -1103,6 +1103,9 @@ public:
|
||||
*/
|
||||
void send_http_response(lib::error_code & ec);
|
||||
|
||||
/// Send deferred HTTP Response
|
||||
void send_http_response();
|
||||
|
||||
// TODO HTTPNBIO: write_headers
|
||||
// function that processes headers + status so far and writes it to the wire
|
||||
// beginning the HTTP response body state. This method will ignore anything
|
||||
|
||||
@@ -516,6 +516,35 @@ public:
|
||||
/// Resume reading of new data
|
||||
void resume_reading(connection_hdl hdl);
|
||||
|
||||
/// Send deferred HTTP Response
|
||||
/**
|
||||
* Sends an http response to an HTTP connection that was deferred. This will
|
||||
* send a complete response including all headers, status line, and body
|
||||
* text. The connection will be closed afterwards.
|
||||
*
|
||||
* Exception free variant
|
||||
*
|
||||
* @since 0.6.0
|
||||
*
|
||||
* @param hdl The connection to send the response on
|
||||
* @param ec A status code, zero on success, non-zero otherwise
|
||||
*/
|
||||
void send_http_response(connection_hdl hdl, lib::error_code & ec);
|
||||
|
||||
/// Send deferred HTTP Response (exception free)
|
||||
/**
|
||||
* Sends an http response to an HTTP connection that was deferred. This will
|
||||
* send a complete response including all headers, status line, and body
|
||||
* text. The connection will be closed afterwards.
|
||||
*
|
||||
* Exception variant
|
||||
*
|
||||
* @since 0.6.0
|
||||
*
|
||||
* @param hdl The connection to send the response on
|
||||
*/
|
||||
void send_http_response(connection_hdl hdl);
|
||||
|
||||
/// Create a message and add it to the outgoing send queue (exception free)
|
||||
/**
|
||||
* Convenience method to send a message given a payload string and an opcode
|
||||
|
||||
@@ -644,10 +644,10 @@ void connection<config>::remove_header(std::string const & key)
|
||||
* Warning: deferred connections won't time out and as a result can tie up
|
||||
* resources.
|
||||
*
|
||||
* @param ec A status code, zero on success, non-zero otherwise
|
||||
* @return A status code, zero on success, non-zero otherwise
|
||||
*/
|
||||
template <typename config>
|
||||
void connection<config>::defer_http_response(lib::error_code & ec) {
|
||||
lib::error_code connection<config>::defer_http_response() {
|
||||
// Cancel handshake timer, otherwise the connection will time out and we'll
|
||||
// close the connection before the app has a chance to send a response.
|
||||
if (m_handshake_timer) {
|
||||
@@ -658,10 +658,10 @@ void connection<config>::defer_http_response(lib::error_code & ec) {
|
||||
// Do something to signal deferral
|
||||
m_http_state = session::http_state::deferred;
|
||||
|
||||
ec = lib::error_code();
|
||||
return lib::error_code();
|
||||
}
|
||||
|
||||
/// Send deferred HTTP Response
|
||||
/// Send deferred HTTP Response (exception free)
|
||||
/**
|
||||
* Sends an http response to an HTTP connection that was deferred. This will
|
||||
* send a complete response including all headers, status line, and body
|
||||
@@ -687,6 +687,15 @@ void connection<config>::send_http_response(lib::error_code & ec) {
|
||||
ec = lib::error_code();
|
||||
}
|
||||
|
||||
template <typename config>
|
||||
void connection<config>::send_http_response() {
|
||||
lib::error_code ec;
|
||||
this->send_http_response(ec);
|
||||
if (ec) {
|
||||
throw exception(ec);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -142,7 +142,21 @@ void endpoint<connection,config>::resume_reading(connection_hdl hdl) {
|
||||
if (ec) { throw exception(ec); }
|
||||
}
|
||||
|
||||
template <typename connection, typename config>
|
||||
void endpoint<connection,config>::send_http_response(connection_hdl hdl,
|
||||
lib::error_code & ec)
|
||||
{
|
||||
connection_ptr con = get_con_from_hdl(hdl,ec);
|
||||
if (ec) {return;}
|
||||
con->send_http_response(ec);
|
||||
}
|
||||
|
||||
template <typename connection, typename config>
|
||||
void endpoint<connection,config>::send_http_response(connection_hdl hdl) {
|
||||
lib::error_code ec;
|
||||
send_http_response(hdl,ec);
|
||||
if (ec) { throw exception(ec); }
|
||||
}
|
||||
|
||||
template <typename connection, typename config>
|
||||
void endpoint<connection,config>::send(connection_hdl hdl, std::string const & payload,
|
||||
|
||||
Reference in new issue
Block a user