Skip to content
Snippets Groups Projects
  1. Apr 19, 2024
  2. Apr 18, 2024
    • Gordan Trevis's avatar
    • Quentin Gliech's avatar
      Helpers to transform Twisted requests to Rust http Requests/Responses (#17081) · 09f0957b
      Quentin Gliech authored
      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(())
      }
      ```
      Unverified
      09f0957b
  3. Apr 17, 2024
  4. Apr 16, 2024
  5. Apr 15, 2024
  6. Apr 12, 2024
  7. Apr 11, 2024
  8. Apr 09, 2024
  9. Apr 08, 2024
  10. Apr 05, 2024
  11. Apr 04, 2024
  12. Apr 02, 2024
  13. Mar 28, 2024
Loading