0
0
mirror of https://github.com/tursodatabase/libsql.git synced 2025-05-30 08:52:41 +00:00

fix namespace bin header ()

* fix warning deprecated cargo config extension

* decode `x-namespace-bin`
This commit is contained in:
ad hoc
2024-05-22 16:23:52 +02:00
committed by GitHub
parent 15a280e29a
commit 21145e0b1b
3 changed files with 10 additions and 4 deletions
.cargo
libsql-server/src

@ -1,5 +1,5 @@
use axum::response::IntoResponse;
use hyper::{header::ToStrError, StatusCode};
use hyper::StatusCode;
use tonic::metadata::errors::InvalidMetadataValueBytes;
use crate::{
@ -69,7 +69,7 @@ pub enum Error {
#[error("Invalid namespace")]
InvalidNamespace,
#[error("Invalid namespace bytes: `{0}`")]
InvalidNamespaceBytes(#[from] ToStrError),
InvalidNamespaceBytes(Box<dyn std::error::Error + Sync + Send + 'static>),
#[error("Replica meta error: {0}")]
ReplicaMetaError(#[from] libsql_replication::meta::Error),
#[error("Replicator error: {0}")]

@ -1,6 +1,7 @@
use std::sync::Arc;
use axum::extract::{FromRequestParts, Path};
use base64::prelude::*;
use hyper::http::request::Parts;
use hyper::HeaderMap;
use libsql_replication::rpc::replication::NAMESPACE_METADATA_KEY;
@ -73,8 +74,13 @@ fn try_namespace_from_host(
fn try_namespace_from_metadata(metadata: &axum::http::HeaderValue) -> Result<NamespaceName, Error> {
metadata
.to_str()
.map_err(|s| Error::InvalidNamespaceBytes(s))
.and_then(|ns| NamespaceName::from_string(ns.into()))
.map_err(|s| Error::InvalidNamespaceBytes(Box::new(s)))
.and_then(|encoded| {
BASE64_STANDARD_NO_PAD
.decode(encoded)
.map_err(|e| Error::InvalidNamespaceBytes(Box::new(e)))
})
.and_then(|ns| NamespaceName::from_bytes(ns.into()))
}
pub struct MakeConnectionExtractorPath(pub Arc<dyn MakeConnection<Connection = Connection>>);