mirror of
https://github.com/MercuryWorkshop/epoxy-tls.git
synced 2025-05-13 06:20:02 -04:00
make websocket errors more verbose
This commit is contained in:
parent
0768cb9502
commit
d6c095fe7b
2 changed files with 37 additions and 29 deletions
|
@ -205,27 +205,34 @@ impl EpoxyWebSocket {
|
|||
// https://github.com/snapview/tungstenite-rs/blob/314feea3055a93e585882fb769854a912a7e6dae/src/handshake/client.rs#L189
|
||||
fn verify(response: &Response<Incoming>) -> Result<(), EpoxyError> {
|
||||
if response.status() != StatusCode::SWITCHING_PROTOCOLS {
|
||||
return Err(EpoxyError::WsInvalidStatusCode);
|
||||
return Err(EpoxyError::WsInvalidStatusCode(
|
||||
response.status().as_u16(),
|
||||
StatusCode::SWITCHING_PROTOCOLS.as_u16(),
|
||||
));
|
||||
}
|
||||
|
||||
let headers = response.headers();
|
||||
|
||||
if !headers
|
||||
let upgrade_header = headers
|
||||
.get(UPGRADE)
|
||||
.and_then(|h| h.to_str().ok())
|
||||
.map(|h| h.eq_ignore_ascii_case("websocket"))
|
||||
.unwrap_or(false)
|
||||
{
|
||||
return Err(EpoxyError::WsInvalidUpgradeHeader);
|
||||
.unwrap_or_default();
|
||||
|
||||
if !upgrade_header.eq_ignore_ascii_case("websocket") {
|
||||
return Err(EpoxyError::WsInvalidUpgradeHeader(
|
||||
upgrade_header.to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
if !headers
|
||||
let connection_header = headers
|
||||
.get(CONNECTION)
|
||||
.and_then(|h| h.to_str().ok())
|
||||
.map(|h| h.eq_ignore_ascii_case("Upgrade"))
|
||||
.unwrap_or(false)
|
||||
{
|
||||
return Err(EpoxyError::WsInvalidConnectionHeader);
|
||||
.unwrap_or_default();
|
||||
|
||||
if !connection_header.eq_ignore_ascii_case("Upgrade") {
|
||||
return Err(EpoxyError::WsInvalidConnectionHeader(
|
||||
connection_header.to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue