summary refs log tree commit diff
path: root/rust/Cargo.toml
diff options
context:
space:
mode:
authorQuentin Gliech <quenting@element.io>2024-04-18 12:20:30 +0200
committerGitHub <noreply@github.com>2024-04-18 12:20:30 +0200
commit09f0957b36cf1b4e9a89f5594df51a853d0dfffe (patch)
tree57ad6eb65d833ed18183a19bbf442d341e6ce37d /rust/Cargo.toml
parentFix remote receipts for events we don't have (#17096) (diff)
downloadsynapse-09f0957b36cf1b4e9a89f5594df51a853d0dfffe.tar.xz
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(())
}
```
Diffstat (limited to 'rust/Cargo.toml')
-rw-r--r--rust/Cargo.toml3
1 files changed, 3 insertions, 0 deletions
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index ba293f8d4f..9ac766182b 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -23,6 +23,9 @@ name = "synapse.synapse_rust"
 
 [dependencies]
 anyhow = "1.0.63"
+bytes = "1.6.0"
+headers = "0.4.0"
+http = "1.1.0"
 lazy_static = "1.4.0"
 log = "0.4.17"
 pyo3 = { version = "0.20.0", features = [