aKode fase 5: rinomina interna (crate akode-*, akode-rs/, akode-cli/, binario akode, AKODE_*, ~/.akode, snapshot)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
40
akode-rs/exec-server/src/client_inbound_request_limit.rs
Normal file
40
akode-rs/exec-server/src/client_inbound_request_limit.rs
Normal file
@@ -0,0 +1,40 @@
|
||||
use akode_exec_server_protocol::EXEC_CLOSED_METHOD;
|
||||
use akode_exec_server_protocol::EXEC_EXITED_METHOD;
|
||||
use akode_exec_server_protocol::EXEC_OUTPUT_DELTA_METHOD;
|
||||
use akode_exec_server_protocol::HTTP_REQUEST_BODY_DELTA_METHOD;
|
||||
use akode_exec_server_protocol::JSONRPCMessage;
|
||||
use akode_exec_server_protocol::MAX_HTTP_BODY_DELTA_BYTES;
|
||||
|
||||
// A transport may materialize one larger frame before its JSON-RPC kind is known.
|
||||
pub(crate) const MAX_CLIENT_INBOUND_REQUEST_LEN: usize = 8 * 1024;
|
||||
// Streamed HTTP bodies carry up to 1 MiB before base64 and JSON-RPC framing.
|
||||
pub(crate) const MAX_CLIENT_INBOUND_NOTIFICATION_LEN: usize = 2 * MAX_HTTP_BODY_DELTA_BYTES;
|
||||
|
||||
pub(crate) fn client_inbound_message_exceeded_limit(
|
||||
message: Result<&JSONRPCMessage, &serde_json::Error>,
|
||||
encoded_len: usize,
|
||||
max_request_len: usize,
|
||||
) -> Option<usize> {
|
||||
let max_len = match message {
|
||||
Ok(JSONRPCMessage::Notification(notification))
|
||||
if matches!(
|
||||
notification.method.as_str(),
|
||||
EXEC_OUTPUT_DELTA_METHOD
|
||||
| EXEC_EXITED_METHOD
|
||||
| EXEC_CLOSED_METHOD
|
||||
| HTTP_REQUEST_BODY_DELTA_METHOD
|
||||
) =>
|
||||
{
|
||||
MAX_CLIENT_INBOUND_NOTIFICATION_LEN
|
||||
}
|
||||
Ok(JSONRPCMessage::Request(_)) | Ok(JSONRPCMessage::Notification(_)) | Err(_) => {
|
||||
max_request_len
|
||||
}
|
||||
Ok(JSONRPCMessage::Response(_)) | Ok(JSONRPCMessage::Error(_)) => return None,
|
||||
};
|
||||
(encoded_len > max_len).then_some(max_len)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "client_inbound_request_limit_tests.rs"]
|
||||
mod tests;
|
||||
Reference in New Issue
Block a user