Skip to content

Commit 52828b4

Browse files
paulobressanverbotenj
authored andcommitted
fix: fixed proxy api key (demeter-run#71)
1 parent fe4a4e6 commit 52828b4

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

proxy/src/proxy.rs

+6-13
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,6 @@ pub struct ProxyRequest {
312312
}
313313
impl ProxyRequest {
314314
pub async fn new(hyper_req: &mut Request<Incoming>, state: &State) -> Option<Self> {
315-
let mut host = get_header(hyper_req, HOST.as_str())?;
316-
let host_regex = host.clone();
317-
318-
let captures = state.host_regex.captures(&host_regex)?;
319-
320315
let namespace = state.config.proxy_namespace.clone();
321316

322317
let protocol = get_header(hyper_req, UPGRADE.as_str())
@@ -329,15 +324,13 @@ impl ProxyRequest {
329324
})
330325
.unwrap_or(Protocol::Http);
331326

332-
if let Some(key) = captures.get(1) {
333-
let key = key.as_str();
334-
hyper_req
335-
.headers_mut()
336-
.insert(DMTR_API_KEY, HeaderValue::from_str(key).unwrap());
337-
host = host.replace(&format!("{key}."), "");
338-
}
327+
let host = get_header(hyper_req, HOST.as_str())?;
328+
let captures = state.host_regex.captures(&host)?;
329+
330+
let token = get_header(hyper_req, DMTR_API_KEY)
331+
.or_else(|| captures.get(1).map(|v| v.as_str().to_string()))
332+
.unwrap_or_default();
339333

340-
let token = get_header(hyper_req, DMTR_API_KEY).unwrap_or_default();
341334
let consumer = state.get_consumer(&token).await?;
342335
let instance = format!(
343336
"ogmios-{}-{}.{}:{}",

0 commit comments

Comments
 (0)