InterviewSolution
| 1. |
Can I Reject Or Conditionally Accept A Connection? |
|
Answer» Yes. The validate handler is called after the initial HANDSHAKE has been RECIEVED but before WebSocket++ has responded. This gives you the opportunity to inspect the incoming connection REQUEST, its headers, origin, subprotocols, and the remote endpoint IP. Return true from the validate handler to accept the connection and false to reject it. To set a custom HTTP error message for your rejection, use websocketpp::connection::set_status and (optionally) websocketpp::connection::set_body() to set the HTTP STATUS code and error message body text. If you do not set body text a message will be generated automatically BASED on the status code. Yes. The validate handler is called after the initial handshake has been recieved but before WebSocket++ has responded. This gives you the opportunity to inspect the incoming connection request, its headers, origin, subprotocols, and the remote endpoint IP. Return true from the validate handler to accept the connection and false to reject it. To set a custom HTTP error message for your rejection, use websocketpp::connection::set_status and (optionally) websocketpp::connection::set_body() to set the HTTP status code and error message body text. If you do not set body text a message will be generated automatically based on the status code. |
|