Skip to content

Commit

Permalink
check handshake method
Browse files Browse the repository at this point in the history
  • Loading branch information
biryukovmaxim committed Jun 18, 2023
1 parent ecc2aee commit da5ed62
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
21 changes: 15 additions & 6 deletions engineioxide/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ pub enum Error {

#[error("http error response: {0:?}")]
HttpErrorResponse(StatusCode),
#[error("unsupported protocol version")]
UnsupportedProtocolVersion,

#[error("transport unknown")]
UnknownTransport,
#[error("bad handshake method")]
BadHandshakeMethod,
#[error("unsupported protocol version")]
UnsupportedProtocolVersion,
}

/// Convert an error into an http response
Expand All @@ -56,16 +59,22 @@ impl<B> From<Error> for Response<ResponseBody<B>> {
.status(400)
.body(ResponseBody::empty_response())
.unwrap(),
Error::UnsupportedProtocolVersion => Response::builder()
Error::UnknownTransport => Response::builder()
.status(400)
.body(ResponseBody::custom_response(
"{\"code\":\"5\",\"message\":\"Unsupported protocol version\"}".into(),
"{\"code\":\"0\",\"message\":\"Transport unknown\"}".into(),
))
.unwrap(),
Error::UnknownTransport => Response::builder()
Error::BadHandshakeMethod => Response::builder()
.status(400)
.body(ResponseBody::custom_response(
"{\"code\":\"0\",\"message\":\"Transport unknown\"}".into(),
"{\"code\":\"2\",\"message\":\"Bad handshake method\"}".into(),
))
.unwrap(),
Error::UnsupportedProtocolVersion => Response::builder()
.status(400)
.body(ResponseBody::custom_response(
"{\"code\":\"5\",\"message\":\"Unsupported protocol version\"}".into(),
))
.unwrap(),
e => {
Expand Down
15 changes: 10 additions & 5 deletions engineioxide/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,17 @@ impl RequestInfo {
.and_then(|s| s.split('=').nth(1))
.ok_or(UnknownTransport)
.and_then(|t| t.parse())?;
let method = req.method().clone();

Ok(RequestInfo {
sid,
transport,
method: req.method().clone(),
})
if !matches!(method, Method::GET) && sid.is_none() {
Err(Error::BadHandshakeMethod)
} else {
Ok(RequestInfo {
sid,
transport,
method,
})
}
}
}

Expand Down

0 comments on commit da5ed62

Please sign in to comment.