Deprecate missing format inference on RPC protocol (#4729)
Co-authored-by: Tobie Morgan Hitchcock <tobie@surrealdb.com>
This commit is contained in:
parent
bd031ccbe8
commit
8f30ee08cf
5 changed files with 17 additions and 6 deletions
|
@ -24,6 +24,7 @@ use uuid::Uuid;
|
||||||
pub(crate) const PATH: &str = "rpc";
|
pub(crate) const PATH: &str = "rpc";
|
||||||
const PING_INTERVAL: Duration = Duration::from_secs(5);
|
const PING_INTERVAL: Duration = Duration::from_secs(5);
|
||||||
const REVISION_HEADER: &str = "revision";
|
const REVISION_HEADER: &str = "revision";
|
||||||
|
const BINCODE_HEADER: &str = "bincode";
|
||||||
|
|
||||||
enum RequestEffect {
|
enum RequestEffect {
|
||||||
/// Completing this request sets a variable to a give value.
|
/// Completing this request sets a variable to a give value.
|
||||||
|
|
|
@ -80,6 +80,10 @@ pub(crate) async fn connect(
|
||||||
request
|
request
|
||||||
.headers_mut()
|
.headers_mut()
|
||||||
.insert(SEC_WEBSOCKET_PROTOCOL, HeaderValue::from_static(super::REVISION_HEADER));
|
.insert(SEC_WEBSOCKET_PROTOCOL, HeaderValue::from_static(super::REVISION_HEADER));
|
||||||
|
} else {
|
||||||
|
request
|
||||||
|
.headers_mut()
|
||||||
|
.insert(SEC_WEBSOCKET_PROTOCOL, HeaderValue::from_static(super::BINCODE_HEADER));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
#[cfg(any(feature = "native-tls", feature = "rustls"))]
|
||||||
|
|
|
@ -2,7 +2,6 @@ use crate::cli::abstraction::auth::Error as SurrealAuthError;
|
||||||
use axum::response::{IntoResponse, Response};
|
use axum::response::{IntoResponse, Response};
|
||||||
use axum::Error as AxumError;
|
use axum::Error as AxumError;
|
||||||
use axum::Json;
|
use axum::Json;
|
||||||
use axum_extra::typed_header::TypedHeaderRejection;
|
|
||||||
use base64::DecodeError as Base64Error;
|
use base64::DecodeError as Base64Error;
|
||||||
use http::{HeaderName, StatusCode};
|
use http::{HeaderName, StatusCode};
|
||||||
use reqwest::Error as ReqwestError;
|
use reqwest::Error as ReqwestError;
|
||||||
|
@ -38,7 +37,7 @@ pub enum Error {
|
||||||
OperationUnsupported,
|
OperationUnsupported,
|
||||||
|
|
||||||
#[error("There was a problem parsing the header {0}: {1}")]
|
#[error("There was a problem parsing the header {0}: {1}")]
|
||||||
InvalidHeader(HeaderName, TypedHeaderRejection),
|
InvalidHeader(HeaderName, String),
|
||||||
|
|
||||||
#[error("There was a problem with the database: {0}")]
|
#[error("There was a problem with the database: {0}")]
|
||||||
Db(#[from] SurrealError),
|
Db(#[from] SurrealError),
|
||||||
|
|
|
@ -58,7 +58,7 @@ where
|
||||||
Ok(TypedHeader(val)) => Ok(Some(val.to_string())),
|
Ok(TypedHeader(val)) => Ok(Some(val.to_string())),
|
||||||
Err(e) => match e.reason() {
|
Err(e) => match e.reason() {
|
||||||
TypedHeaderRejectionReason::Missing => Ok(None),
|
TypedHeaderRejectionReason::Missing => Ok(None),
|
||||||
_ => Err(Error::InvalidHeader(H::name().to_owned(), e)),
|
_ => Err(Error::InvalidHeader(H::name().to_owned(), e.to_string())),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,8 @@ use axum::{
|
||||||
use axum_extra::headers::Header;
|
use axum_extra::headers::Header;
|
||||||
use axum_extra::TypedHeader;
|
use axum_extra::TypedHeader;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
|
use http::header::SEC_WEBSOCKET_PROTOCOL;
|
||||||
use http::HeaderMap;
|
use http::HeaderMap;
|
||||||
use http::HeaderValue;
|
|
||||||
use surrealdb::dbs::Session;
|
use surrealdb::dbs::Session;
|
||||||
use surrealdb::kvs::Datastore;
|
use surrealdb::kvs::Datastore;
|
||||||
use surrealdb::rpc::format::Format;
|
use surrealdb::rpc::format::Format;
|
||||||
|
@ -54,6 +54,13 @@ async fn get_handler(
|
||||||
State(rpc_state): State<Arc<RpcState>>,
|
State(rpc_state): State<Arc<RpcState>>,
|
||||||
headers: HeaderMap,
|
headers: HeaderMap,
|
||||||
) -> Result<impl IntoResponse, impl IntoResponse> {
|
) -> Result<impl IntoResponse, impl IntoResponse> {
|
||||||
|
// Check that a valid header has been specified
|
||||||
|
if headers.get(SEC_WEBSOCKET_PROTOCOL).is_none() {
|
||||||
|
warn!("A connection was made without a specified protocol.");
|
||||||
|
warn!("Automatic inference of the protocol format is deprecated in SurrealDB 2.0 and will be removed in SurrealDB 3.0.");
|
||||||
|
warn!("Please upgrade any client to ensure that the connection format is specified.");
|
||||||
|
}
|
||||||
|
|
||||||
// Check if there is a connection id header specified
|
// Check if there is a connection id header specified
|
||||||
let id = match headers.get(SurrealId::name()) {
|
let id = match headers.get(SurrealId::name()) {
|
||||||
// Use the specific SurrealDB id header when provided
|
// Use the specific SurrealDB id header when provided
|
||||||
|
@ -119,9 +126,9 @@ async fn handle_socket(
|
||||||
id: Uuid,
|
id: Uuid,
|
||||||
) {
|
) {
|
||||||
// Check if there is a WebSocket protocol specified
|
// Check if there is a WebSocket protocol specified
|
||||||
let format = match ws.protocol().map(HeaderValue::to_str) {
|
let format = match ws.protocol().and_then(|h| h.to_str().ok()) {
|
||||||
// Any selected protocol will always be a valie value
|
// Any selected protocol will always be a valie value
|
||||||
Some(protocol) => protocol.unwrap().into(),
|
Some(protocol) => protocol.into(),
|
||||||
// No protocol format was specified
|
// No protocol format was specified
|
||||||
_ => Format::None,
|
_ => Format::None,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue