Skip to content

Commit

Permalink
fix panic on bad http path prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
erebe committed Dec 14, 2024
1 parent 07d38ca commit 30cd4a7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/tunnel/transport/http2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
10 changes: 9 additions & 1 deletion src/tunnel/transport/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 30cd4a7

Please sign in to comment.