This commit is contained in:
timokoesters 2020-04-19 14:14:47 +02:00
parent 4d658b3952
commit 80ddf80f17
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
10 changed files with 632 additions and 141 deletions

25
src/server_server.rs Normal file
View file

@ -0,0 +1,25 @@
use std::convert::TryInto;
pub fn send_request<T: TryInto<http::Request<Vec<u8>>>>(
data: &crate::Data,
method: http::Method,
uri: String,
destination: String,
request: T,
) where
T::Error: std::fmt::Debug,
{
let mut http_request: http::Request<_> = request.try_into().unwrap();
let request_json = serde_json::to_value(http_request.body()).unwrap();
let request_map = request_json.as_object_mut().unwrap();
request_map.insert("method".to_owned(), method.to_string().into());
request_map.insert("uri".to_owned(), uri.to_string().into());
//TODO: request_map.insert("origin".to_owned(), data.origin().to_string().into());
request_map.insert("destination".to_owned(), destination.to_string().into());
ruma_signatures::sign_json(data.hostname(), data.keypair(), &mut request_json).unwrap();
let signature = request_json["signatures"];
data.reqwest_client().execute(http_request.into());
}