fix panic on bad http path prefix

This commit is contained in:
Σrebe - Romain GERARD 2024-12-14 21:51:49 +01:00
parent 07d38cae6c
commit 30cd4a72b9
No known key found for this signature in database
GPG key ID: 7A42B4B97E0332F4
2 changed files with 18 additions and 2 deletions

View file

@ -156,7 +156,15 @@ pub async fn connect(
.header(CONTENT_TYPE, "application/json")
.version(hyper::Version::HTTP_2);
let headers = req.headers_mut().unwrap();
let headers = match req.headers_mut() {
Some(h) => h,
None => {
return Err(anyhow!(
"failed to build HTTP request to contact the server {:?}. Most likely path_prefix `{}` or http headers is not valid",
req, client.config.http_upgrade_path_prefix
))
}
};
for (k, v) in &client.config.http_headers {
let _ = headers.remove(k);
headers.append(k, v.clone());

View file

@ -257,7 +257,15 @@ pub async fn connect(
)
.version(hyper::Version::HTTP_11);
let headers = req.headers_mut().unwrap();
let headers = match req.headers_mut() {
Some(h) => h,
None => {
return Err(anyhow!(
"failed to build HTTP request to contact the server {:?}. Most likely path_prefix `{}` or http headers is not valid",
req.body(Empty::<Bytes>::new()), client_cfg.http_upgrade_path_prefix
))
}
};
for (k, v) in &client_cfg.http_headers {
let _ = headers.remove(k);
headers.append(k, v.clone());