diff --git a/src/tunnel/transport/http2.rs b/src/tunnel/transport/http2.rs index 86c6a04..80ad7b2 100644 --- a/src/tunnel/transport/http2.rs +++ b/src/tunnel/transport/http2.rs @@ -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()); diff --git a/src/tunnel/transport/websocket.rs b/src/tunnel/transport/websocket.rs index 3f53453..049a78b 100644 --- a/src/tunnel/transport/websocket.rs +++ b/src/tunnel/transport/websocket.rs @@ -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::::new()), client_cfg.http_upgrade_path_prefix + )) + } + }; for (k, v) in &client_cfg.http_headers { let _ = headers.remove(k); headers.append(k, v.clone());