feat(extension): extract http request part into rmcp extension (#163)
* feat(extension): extract http request part into rmcp extension * perf(extension): insert extension from one entrypoint
This commit is contained in:
parent
546490a95e
commit
787cc015b7
1 changed files with 67 additions and 8 deletions
|
|
@ -4,8 +4,8 @@ use serde::{Deserialize, Serialize};
|
|||
use serde_json::Value;
|
||||
|
||||
use super::{
|
||||
ClientNotification, ClientRequest, Extensions, JsonObject, NumberOrString, ProgressToken,
|
||||
ServerNotification, ServerRequest,
|
||||
ClientNotification, ClientRequest, Extensions, JsonObject, JsonRpcMessage, NumberOrString,
|
||||
ProgressToken, ServerNotification, ServerRequest,
|
||||
};
|
||||
|
||||
pub trait GetMeta {
|
||||
|
|
@ -153,3 +153,42 @@ impl DerefMut for Meta {
|
|||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<Req, Resp, Noti> JsonRpcMessage<Req, Resp, Noti>
|
||||
where
|
||||
Req: GetExtensions,
|
||||
Noti: GetExtensions,
|
||||
{
|
||||
pub fn insert_extension<T: Clone + Send + Sync + 'static>(&mut self, value: T) {
|
||||
match self {
|
||||
JsonRpcMessage::Request(json_rpc_request) => {
|
||||
json_rpc_request.request.extensions_mut().insert(value);
|
||||
}
|
||||
JsonRpcMessage::Notification(json_rpc_notification) => {
|
||||
json_rpc_notification
|
||||
.notification
|
||||
.extensions_mut()
|
||||
.insert(value);
|
||||
}
|
||||
JsonRpcMessage::BatchRequest(json_rpc_batch_request_items) => {
|
||||
for item in json_rpc_batch_request_items {
|
||||
match item {
|
||||
super::JsonRpcBatchRequestItem::Request(json_rpc_request) => {
|
||||
json_rpc_request
|
||||
.request
|
||||
.extensions_mut()
|
||||
.insert(value.clone());
|
||||
}
|
||||
super::JsonRpcBatchRequestItem::Notification(json_rpc_notification) => {
|
||||
json_rpc_notification
|
||||
.notification
|
||||
.extensions_mut()
|
||||
.insert(value.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue