mirror of
https://github.com/oxen-io/session-open-group-server.git
synced 2023-12-13 20:30:35 +01:00
Fix RPC call parsing
This commit is contained in:
parent
fbc7c22f3d
commit
7478c4a312
|
@ -35,14 +35,7 @@ pub async fn handle_onion_request(blob: warp::hyper::body::Bytes) -> Result<Resp
|
|||
}
|
||||
|
||||
async fn handle_decrypted_onion_request(plaintext: &[u8], symmetric_key: &[u8]) -> Result<Response, Rejection> {
|
||||
let json = match String::from_utf8(plaintext.to_vec()) {
|
||||
Ok(json) => json,
|
||||
Err(e) => {
|
||||
println!("Couldn't parse RPC call from JSON due to error: {}.", e);
|
||||
return Err(warp::reject::custom(Error::InvalidOnionRequest));
|
||||
}
|
||||
};
|
||||
let rpc_call = match serde_json::from_str(&json) {
|
||||
let rpc_call = match serde_json::from_slice(plaintext) {
|
||||
Ok(rpc_call) => rpc_call,
|
||||
Err(e) => {
|
||||
println!("Couldn't parse RPC call from JSON due to error: {}.", e);
|
||||
|
|
16
src/rpc.rs
16
src/rpc.rs
|
@ -1,6 +1,6 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use warp::{Rejection, reply::Reply, reply::Response};
|
||||
|
||||
use super::errors::Error;
|
||||
|
@ -12,7 +12,7 @@ pub struct RpcCall {
|
|||
pub endpoint: String,
|
||||
pub body: String,
|
||||
pub method: String,
|
||||
pub headers: String
|
||||
pub headers: HashMap<String, String>
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
|
@ -217,20 +217,12 @@ async fn handle_delete_request(rpc_call: RpcCall, uri: http::Uri, auth_token: Op
|
|||
|
||||
fn get_auth_token(rpc_call: &RpcCall) -> Option<String> {
|
||||
if rpc_call.headers.is_empty() { return None; }
|
||||
let headers: HashMap<String, String> = match serde_json::from_str(&rpc_call.headers) {
|
||||
Ok(headers) => headers,
|
||||
Err(_) => return None
|
||||
};
|
||||
return headers.get("Authorization").map(|s| s.to_string());
|
||||
return rpc_call.headers.get("Authorization").map(|s| s.to_string());
|
||||
}
|
||||
|
||||
fn get_room_id(rpc_call: &RpcCall) -> Option<isize> {
|
||||
if rpc_call.headers.is_empty() { return None; }
|
||||
let headers: HashMap<String, String> = match serde_json::from_str(&rpc_call.headers) {
|
||||
Ok(headers) => headers,
|
||||
Err(_) => return None
|
||||
};
|
||||
let header = headers.get("Room")?;
|
||||
let header = rpc_call.headers.get("Room")?;
|
||||
match header.parse() {
|
||||
Ok(room_id) => return Some(room_id),
|
||||
Err(_) => return None
|
||||
|
|
Loading…
Reference in a new issue