Skip to content

Commit

Permalink
handle unwrap in network crate
Browse files Browse the repository at this point in the history
  • Loading branch information
SajjadPourali committed Aug 24, 2023
1 parent cb102f8 commit 1b4ecbd
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions network/src/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ impl WsConnection {
tungstenite::handshake::client::generate_key(),
);
for (key, value) in headers.iter() {
let headers = request.headers_mut().unwrap();
headers.insert(*key, HeaderValue::from_str(value).unwrap());
if let Ok(header_value) = HeaderValue::from_str(value) {
request
.headers_mut()
.and_then(|headers| headers.insert(*key, header_value));
}
}
let request = request.method("GET").body(Body::from(""))?;
let response = request_sender.send_request(request).await?;
Expand Down Expand Up @@ -375,8 +378,11 @@ impl WsConnectionBinary {
tungstenite::handshake::client::generate_key(),
);
for (key, value) in headers.iter() {
let headers = request.headers_mut().unwrap();
headers.insert(*key, HeaderValue::from_str(value).unwrap());
if let Ok(header_value) = HeaderValue::from_str(value) {
request
.headers_mut()
.and_then(|headers| headers.insert(*key, header_value));
}
}
let request = request.method("GET").body(Body::from(""))?;
let response = request_sender.send_request(request).await?;
Expand Down

0 comments on commit 1b4ecbd

Please sign in to comment.