synapse/rust/src
Quentin Gliech 09f0957b36
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(())
}
```
2024-04-18 12:20:30 +02:00
..
acl Correctly mention previous copyright (#16820) 2024-01-23 11:26:48 +00:00
events Port EventInternalMetadata class to Rust (#16782) 2024-01-08 14:06:48 +00:00
push #17039 Issue: Update base_rules.rs (#17043) 2024-04-09 14:07:26 +01:00
errors.rs Helpers to transform Twisted requests to Rust http Requests/Responses (#17081) 2024-04-18 12:20:30 +02:00
http.rs Helpers to transform Twisted requests to Rust http Requests/Responses (#17081) 2024-04-18 12:20:30 +02:00
lib.rs Helpers to transform Twisted requests to Rust http Requests/Responses (#17081) 2024-04-18 12:20:30 +02:00