-
- Downloads
Helpers to transform Twisted requests to Rust http Requests/Responses (#17081)
This adds functions to transform a Twisted request to the `http::Request`, and then to send back an `http::Response` through it. It also imports the SynapseError exception so that we can throw that from Rust code directly Example usage of this would be: ```rust use crate::http::{http_request_from_twisted, http_response_to_twisted, HeaderMapPyExt}; fn handler(twisted_request: &PyAny) -> PyResult<()> { let request = http_request_from_twisted(twisted_request)?; let ua: headers::UserAgent = request.headers().typed_get_required()?; if whatever { return Err((crate::errors::SynapseError::new( StatusCode::UNAUTHORIZED, "Whatever".to_owned "M_UNAUTHORIZED", None, None, ))); } let response = Response::new("hello".as_bytes()); http_response_to_twisted(twisted_request, response)?; Ok(()) } ```
Showing
- Cargo.lock 90 additions, 2 deletionsCargo.lock
- changelog.d/17081.misc 1 addition, 0 deletionschangelog.d/17081.misc
- rust/Cargo.toml 3 additions, 0 deletionsrust/Cargo.toml
- rust/src/errors.rs 60 additions, 0 deletionsrust/src/errors.rs
- rust/src/http.rs 165 additions, 0 deletionsrust/src/http.rs
- rust/src/lib.rs 2 additions, 0 deletionsrust/src/lib.rs
changelog.d/17081.misc
0 → 100644
rust/src/errors.rs
0 → 100644
rust/src/http.rs
0 → 100644
Please register or sign in to comment