Version the zrpc protocol using a X-ZRPC-VERSION header

This commit is contained in:
Antonio Scandurra
2021-09-23 15:35:35 +02:00
parent a1ca507498
commit 511cbaa2bd
3 changed files with 36 additions and 20 deletions
+4 -1
View File
@@ -894,8 +894,11 @@ pub fn add_routes(app: &mut tide::Server<Arc<AppState>>, rpc: &Arc<Peer>) {
let connection_upgrade = header_contains_ignore_case(&request, CONNECTION, "upgrade");
let upgrade_to_websocket = header_contains_ignore_case(&request, UPGRADE, "websocket");
let upgrade_requested = connection_upgrade && upgrade_to_websocket;
let client_protocol_version: Option<u32> = request
.header("X-ZRPC-VERSION")
.and_then(|v| v.as_str().parse().ok());
if !upgrade_requested {
if !upgrade_requested || client_protocol_version != Some(zrpc::VERSION) {
return Ok(Response::new(StatusCode::UpgradeRequired));
}