Skip to content

Commit

Permalink
Add code item to websocket.disconnect event
Browse files Browse the repository at this point in the history
  • Loading branch information
gi0baro committed Jan 24, 2024
1 parent d46cf7b commit a87d700
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/asgi/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,14 @@ fn ws_message_into_py(message: Message) -> PyResult<PyObject> {
dict.set_item(pyo3::intern!(py, "text"), message)?;
Ok(dict.to_object(py))
}),
Message::Close(_) => Python::with_gil(|py| {
Message::Close(frame) => Python::with_gil(|py| {
let close_code: u16 = match frame {
Some(frame) => frame.code.into(),
_ => 1005,
};
let dict = PyDict::new(py);
dict.set_item(pyo3::intern!(py, "type"), pyo3::intern!(py, "websocket.disconnect"))?;
dict.set_item(pyo3::intern!(py, "code"), close_code)?;
Ok(dict.to_object(py))
}),
v => {
Expand Down

0 comments on commit a87d700

Please sign in to comment.