Skip to content

Commit

Permalink
🔧 Add header on detector requests (#283)
Browse files Browse the repository at this point in the history
* ⬆️ Upgrade uuid crate

Signed-off-by: Evaline Ju <[email protected]>

* 🔧 Add x-model-name header on detector requests

Signed-off-by: Evaline Ju <[email protected]>

* ♻️ Use http header constant

Signed-off-by: Evaline Ju <[email protected]>

---------

Signed-off-by: Evaline Ju <[email protected]>
  • Loading branch information
evaline-ju authored Jan 23, 2025
1 parent 87361ac commit 408badf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ tracing = "0.1.41"
tracing-opentelemetry = "0.28.0"
tracing-subscriber = { version = "0.3.19", features = ["json", "env-filter"] }
url = "2.5.4"
uuid = { version = "1.10.0", features = ["v4"] }
uuid = { version = "1.12.1", features = ["v4"] }

[build-dependencies]
tonic-build = "0.12.3"
Expand Down
6 changes: 5 additions & 1 deletion src/clients/detector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use std::fmt::Debug;

use axum::http::HeaderMap;
use http::header::CONTENT_TYPE;
use hyper::StatusCode;
use serde::Deserialize;
use tracing::instrument;
Expand All @@ -39,6 +40,7 @@ pub use text_generation::*;

const DEFAULT_PORT: u16 = 8080;
pub const DETECTOR_ID_HEADER_NAME: &str = "detector-id";
const MODEL_HEADER_NAME: &str = "x-model-name";

#[derive(Debug, Clone, Deserialize)]
pub struct DetectorError {
Expand Down Expand Up @@ -87,7 +89,9 @@ impl<C: DetectorClient + HttpClientExt> DetectorClientExt for C {
) -> Result<U, Error> {
let mut headers = headers;
headers.append(DETECTOR_ID_HEADER_NAME, model_id.parse().unwrap());
headers.append("content-type", "application/json".parse().unwrap());
headers.append(CONTENT_TYPE, "application/json".parse().unwrap());
// Header used by a router component, if available
headers.append(MODEL_HEADER_NAME, model_id.parse().unwrap());

let response = self.inner().post(url, headers, request).await?;

Expand Down

0 comments on commit 408badf

Please sign in to comment.