fix(appservice): Respond with a non-stringified empty object
warp::reply::json() serializes its argument to JSON, passing it an
already-serialized JSON string doesn't do the right thing.
@@ -164,9 +164,13 @@ mod filters {
mod handlers {
use percent_encoding::percent_decode_str;
+ use serde::Serialize;
use super::*;
+ #[derive(Serialize)]
+ struct EmptyObject {}
+
pub async fn user(
user_id: String,
appservice: AppService,
@@ -177,12 +181,12 @@ mod handlers {
let request = query_user::IncomingRequest::try_from_http_request(request, &[user_id])
.map_err(Error::from)?;
return if user_exists(appservice.clone(), request).await {
- Ok(warp::reply::json(&String::from("{}")))
+ Ok(warp::reply::json(&EmptyObject {}))
} else {
Err(warp::reject::not_found())
};
}
- Ok(warp::reply::json(&String::from("{}")))
+ Ok(warp::reply::json(&EmptyObject {}))
}
pub async fn room(
@@ -195,12 +199,12 @@ mod handlers {
let request = query_room::IncomingRequest::try_from_http_request(request, &[room_id])
.map_err(Error::from)?;
return if room_exists(appservice.clone(), request).await {
- Ok(warp::reply::json(&String::from("{}")))
+ Ok(warp::reply::json(&EmptyObject {}))
} else {
Err(warp::reject::not_found())
};
}
- Ok(warp::reply::json(&String::from("{}")))
+ Ok(warp::reply::json(&EmptyObject {}))
}
pub async fn transaction(
@@ -213,7 +217,7 @@ mod handlers {
.map_err(Error::from)?;
appservice.receive_transaction(incoming_transaction).await?;
- Ok(warp::reply::json(&String::from("{}")))
+ Ok(warp::reply::json(&EmptyObject {}))
}
}
