Skip to content

Commit 21145e0

Browse files
authored
fix namespace bin header (#1406)
* fix warning deprecated cargo config extension * decode `x-namespace-bin`
1 parent 15a280e commit 21145e0

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

File renamed without changes.

libsql-server/src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use axum::response::IntoResponse;
2-
use hyper::{header::ToStrError, StatusCode};
2+
use hyper::StatusCode;
33
use tonic::metadata::errors::InvalidMetadataValueBytes;
44

55
use crate::{
@@ -69,7 +69,7 @@ pub enum Error {
6969
#[error("Invalid namespace")]
7070
InvalidNamespace,
7171
#[error("Invalid namespace bytes: `{0}`")]
72-
InvalidNamespaceBytes(#[from] ToStrError),
72+
InvalidNamespaceBytes(Box<dyn std::error::Error + Sync + Send + 'static>),
7373
#[error("Replica meta error: {0}")]
7474
ReplicaMetaError(#[from] libsql_replication::meta::Error),
7575
#[error("Replicator error: {0}")]

libsql-server/src/http/user/db_factory.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::sync::Arc;
22

33
use axum::extract::{FromRequestParts, Path};
4+
use base64::prelude::*;
45
use hyper::http::request::Parts;
56
use hyper::HeaderMap;
67
use libsql_replication::rpc::replication::NAMESPACE_METADATA_KEY;
@@ -73,8 +74,13 @@ fn try_namespace_from_host(
7374
fn try_namespace_from_metadata(metadata: &axum::http::HeaderValue) -> Result<NamespaceName, Error> {
7475
metadata
7576
.to_str()
76-
.map_err(|s| Error::InvalidNamespaceBytes(s))
77-
.and_then(|ns| NamespaceName::from_string(ns.into()))
77+
.map_err(|s| Error::InvalidNamespaceBytes(Box::new(s)))
78+
.and_then(|encoded| {
79+
BASE64_STANDARD_NO_PAD
80+
.decode(encoded)
81+
.map_err(|e| Error::InvalidNamespaceBytes(Box::new(e)))
82+
})
83+
.and_then(|ns| NamespaceName::from_bytes(ns.into()))
7884
}
7985

8086
pub struct MakeConnectionExtractorPath(pub Arc<dyn MakeConnection<Connection = Connection>>);

0 commit comments

Comments
 (0)