mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
Updates on_http and validate handlers to use new handler interface
This commit is contained in:
@@ -142,10 +142,10 @@ public:
|
||||
typedef typename connection::ptr connection_ptr;
|
||||
typedef typename config::message_type::ptr message_ptr;
|
||||
|
||||
virtual void http(connection_ptr con) {}
|
||||
//virtual void http(connection_ptr con) {}
|
||||
|
||||
// TODO: validate is server only. hide from client handlers?
|
||||
virtual bool validate(connection_ptr con) {return true;}
|
||||
//virtual bool validate(connection_ptr con) {return true;}
|
||||
|
||||
//virtual void on_inturrupt(connection_ptr con) {}
|
||||
|
||||
@@ -309,6 +309,37 @@ public:
|
||||
m_interrupt_handler = h;
|
||||
}
|
||||
|
||||
/// Set http handler
|
||||
/**
|
||||
* The http handler is called after an HTTP request other than a WebSocket
|
||||
* upgrade request is received. It allows a WebSocket++ server to respond
|
||||
* to regular HTTP requests on the same port as it processes WebSocket
|
||||
* connections. This can be useful for hosting error messages, flash
|
||||
* policy files, status pages, and other simple HTTP responses. It is not
|
||||
* intended to be used as a primary web server.
|
||||
*
|
||||
* @param h The new http_handler
|
||||
*/
|
||||
void set_http_handler(http_handler h) {
|
||||
m_http_handler = h;
|
||||
}
|
||||
|
||||
/// Set validate handler
|
||||
/**
|
||||
* The validate handler is called after a WebSocket handshake has been
|
||||
* parsed but before a response is returned. It provides the application
|
||||
* a chance to examine the request and determine whether or not it wants
|
||||
* to accept the connection.
|
||||
*
|
||||
* Returning false from the validate handler will reject the connection.
|
||||
* If no validate handler is present, all connections will be allowed.
|
||||
*
|
||||
* @param h The new validate_handler
|
||||
*/
|
||||
void set_validate_handler(validate_handler h) {
|
||||
m_validate_handler = h;
|
||||
}
|
||||
|
||||
/// Set new connection handler
|
||||
/**
|
||||
* Will invoke the old handler's on_unload callback followed by the
|
||||
@@ -799,6 +830,8 @@ private:
|
||||
pong_handler m_pong_handler;
|
||||
pong_timeout_handler m_pong_timeout_handler;
|
||||
interrupt_handler m_interrupt_handler;
|
||||
http_handler m_http_handler;
|
||||
validate_handler m_validate_handler;
|
||||
|
||||
/// Legacy Handler
|
||||
handler_ptr m_handler;
|
||||
|
||||
@@ -123,6 +123,8 @@ public:
|
||||
m_pong_timeout_handler = h;
|
||||
}
|
||||
void set_interrupt_handler(interrupt_handler h) {m_interrupt_handler = h;}
|
||||
void set_http_handler(http_handler h) {m_http_handler = h;}
|
||||
void set_validate_handler(validate_handler h) {m_validate_handler = h;}
|
||||
|
||||
/*************************************/
|
||||
/* Connection pass through functions */
|
||||
@@ -181,6 +183,8 @@ private:
|
||||
pong_handler m_pong_handler;
|
||||
pong_timeout_handler m_pong_timeout_handler;
|
||||
interrupt_handler m_interrupt_handler;
|
||||
http_handler m_http_handler;
|
||||
validate_handler m_validate_handler;
|
||||
|
||||
// endpoint resources
|
||||
std::set<connection_ptr> m_connections;
|
||||
|
||||
@@ -762,7 +762,9 @@ bool connection<config>::process_handshake_request() {
|
||||
// this is not a websocket handshake. Process as plain HTTP
|
||||
std::cout << "HTTP REQUEST" << std::endl;
|
||||
|
||||
m_handler->http(type::shared_from_this());
|
||||
if (m_http_handler) {
|
||||
m_http_handler(m_connection_hdl);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -809,7 +811,7 @@ bool connection<config>::process_handshake_request() {
|
||||
}
|
||||
|
||||
// Ask application to validate the connection
|
||||
if (m_handler->validate(type::shared_from_this())) {
|
||||
if (!m_validate_handler || m_validate_handler(m_connection_hdl)) {
|
||||
m_response.set_status(http::status_code::SWITCHING_PROTOCOLS);
|
||||
|
||||
// Write the appropriate response headers based on request and
|
||||
|
||||
@@ -65,6 +65,8 @@ endpoint<connection,config>::create_connection() {
|
||||
con->set_pong_handler(m_pong_handler);
|
||||
con->set_pong_timeout_handler(m_pong_timeout_handler);
|
||||
con->set_interrupt_handler(m_interrupt_handler);
|
||||
con->set_http_handler(m_http_handler);
|
||||
con->set_validate_handler(m_validate_handler);
|
||||
|
||||
con->set_termination_handler(
|
||||
lib::bind(
|
||||
|
||||
Reference in New Issue
Block a user