Skip to main content

folk_plugin_http/
lib.rs

1pub mod config;
2pub mod hooks;
3pub mod payload;
4pub mod plugin;
5pub mod server;
6
7use anyhow::{Context, Result};
8use folk_api::{Plugin, PluginFactory, ServerPluginWrapper};
9use serde_json::Value;
10
11pub use config::HttpConfig;
12pub use plugin::HttpPlugin;
13
14struct HttpPluginFactory;
15
16impl PluginFactory for HttpPluginFactory {
17    fn create(&self, config: Value) -> Result<Box<dyn Plugin>> {
18        let config: HttpConfig =
19            serde_json::from_value(config).context("invalid [http] configuration")?;
20        if config.compression.min_size > usize::from(u16::MAX) {
21            anyhow::bail!(
22                "invalid [http] configuration: compression.min_size {} exceeds the maximum \
23                 allowed value of {} (65535 bytes); use a value ≤ 65535",
24                config.compression.min_size,
25                u16::MAX,
26            );
27        }
28        Ok(Box::new(ServerPluginWrapper::new(HttpPlugin::new(config))))
29    }
30}
31
32pub fn folk_plugin_factory() -> Box<dyn PluginFactory> {
33    Box::new(HttpPluginFactory)
34}