-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2720124
commit 8c26ce4
Showing
6 changed files
with
106 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2023 Greptime Team | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use core::str; | ||
use std::result::Result as StdResult; | ||
|
||
use axum::async_trait; | ||
use axum::extract::FromRequestParts; | ||
use axum::http::request::Parts; | ||
use axum::http::StatusCode; | ||
use http::HeaderValue; | ||
|
||
use crate::http::header::constants::GREPTIME_LOG_TABLE_NAME_HEADER_NAME; | ||
|
||
pub struct TableName(pub Option<String>); | ||
|
||
#[async_trait] | ||
impl<S> FromRequestParts<S> for TableName | ||
where | ||
S: Send + Sync, | ||
{ | ||
type Rejection = (StatusCode, String); | ||
|
||
async fn from_request_parts(parts: &mut Parts, _state: &S) -> StdResult<Self, Self::Rejection> { | ||
let table_name = parts.headers.get(GREPTIME_LOG_TABLE_NAME_HEADER_NAME); | ||
|
||
match table_name { | ||
Some(name) => Ok(TableName(Some(pipeline_header_error( | ||
name, | ||
GREPTIME_LOG_TABLE_NAME_HEADER_NAME, | ||
)?))), | ||
None => Ok(TableName(None)), | ||
} | ||
} | ||
} | ||
|
||
pub(crate) fn pipeline_header_error( | ||
header: &HeaderValue, | ||
key: &str, | ||
) -> StdResult<String, (http::StatusCode, String)> { | ||
let header_utf8 = str::from_utf8(header.as_bytes()); | ||
match header_utf8 { | ||
Ok(s) => Ok(s.to_string()), | ||
Err(_) => Err(( | ||
StatusCode::BAD_REQUEST, | ||
format!("`{}` header is not valid UTF-8 string type.", key), | ||
)), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters