Skip to content

Commit

Permalink
decode x-namespace-bin
Browse files Browse the repository at this point in the history
  • Loading branch information
MarinPostma committed May 22, 2024
1 parent b640749 commit df6a55c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions libsql-server/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use axum::response::IntoResponse;
use hyper::{header::ToStrError, StatusCode};
use hyper::StatusCode;
use tonic::metadata::errors::InvalidMetadataValueBytes;

use crate::{
Expand Down Expand Up @@ -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}")]
Expand Down
10 changes: 8 additions & 2 deletions libsql-server/src/http/user/db_factory.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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>>);
Expand Down

0 comments on commit df6a55c

Please sign in to comment.