iggy
iggy copied to clipboard
Configurable message size threshold
pub const MAX_HEADERS_SIZE: u32 = 100 * 1024;
pub const MAX_PAYLOAD_SIZE: u32 = 10 * 1024 * 1024;
do you think both fields should be configurable?
Yes, this could be useful for some users I guess.
I've taken a look at this and I am running into some issues.
Since the config is not stored in a global, we cannot easily access it within the Validatable
trait (where it is required to be used). I tried to extend it to:
pub trait Validatable<E, Ops> {
fn validate(&self, options: Ops): Result<(), E>;
}
// calling it:
impl Validatable<Error, (usize, usize)> for XXXCommand {
fn validate(&self, options: (usize, usize)) -> Result<(), Error> {
// ...
}
}
command.validate((max_headers_size, max_payload_size))?
// and without options for other commands
impl Validatable<Error, ()> for XXXCommand {
fn validate(&self, _: ()) -> Result<(), Error> {
// ...
}
}
command.validate(())? // `()` is used here since `!` is still experimental as a type
Which makes it possible to supply additional validation options, but then I also noticed a MAX_NAME_LENGTH
constant which would also be nice inside this configuration. However, that validation happens within the FromStr
trait, which is outside of our control.
I'd suggest to store the config within a global and move the MAX_NAME_LENGTH
to the config. The other option is to keep the MAX_NAME_LENGTH
non-configurable, but that seems inconsistent to me.
Also, open to other ideas ofcourse.