Don't panic on upgrade errors

This commit is contained in:
Brian Picciano 2024-02-28 16:30:08 +01:00
parent 907ea5b7f4
commit 29ea682d8f

View File

@ -137,7 +137,7 @@ fn forward_uri<B>(forward_url: &str, req: &Request<B>) -> String {
let split_url = forward_url.split('?').collect::<Vec<&str>>(); let split_url = forward_url.split('?').collect::<Vec<&str>>();
let mut base_url: &str = split_url.get(0).unwrap_or(&""); let mut base_url: &str = split_url.first().unwrap_or(&"");
let forward_url_query: &str = split_url.get(1).unwrap_or(&""); let forward_url_query: &str = split_url.get(1).unwrap_or(&"");
let path2 = req.uri().path(); let path2 = req.uri().path();
@ -320,19 +320,18 @@ pub async fn call<'a, T: Connect + Clone + Send + Sync + 'static>(
response response
.extensions_mut() .extensions_mut()
.remove::<OnUpgrade>() .remove::<OnUpgrade>()
.expect("response does not have an upgrade extension") .ok_or(ProxyError::UpgradeError(
"Failed to upgrade response".to_string(),
))?
.await?, .await?,
); );
debug!("Responding to a connection upgrade response"); debug!("Responding to a connection upgrade response");
tokio::spawn(async move { let mut request_upgraded = TokioIo::new(request_upgraded.await?);
let mut request_upgraded =
TokioIo::new(request_upgraded.await.expect("failed to upgrade request"));
copy_bidirectional(&mut response_upgraded, &mut request_upgraded) tokio::spawn(async move {
.await copy_bidirectional(&mut response_upgraded, &mut request_upgraded).await
.expect("coping between upgraded connections failed");
}); });
Ok(response) Ok(response)