folk-plugin-http 0.3.9

HTTP plugin for Folk — accepts connections via hyper and dispatches to PHP workers
Documentation
pub mod config;
pub mod hooks;
pub mod payload;
pub mod plugin;
pub mod server;

use anyhow::{Context, Result};
use folk_api::{Plugin, PluginFactory, ServerPluginWrapper};
use serde_json::Value;

pub use config::HttpConfig;
pub use plugin::HttpPlugin;

struct HttpPluginFactory;

impl PluginFactory for HttpPluginFactory {
    fn create(&self, config: Value) -> Result<Box<dyn Plugin>> {
        let config: HttpConfig =
            serde_json::from_value(config).context("invalid [http] configuration")?;
        if config.compression.min_size > usize::from(u16::MAX) {
            anyhow::bail!(
                "invalid [http] configuration: compression.min_size {} exceeds the maximum \
                 allowed value of {} (65535 bytes); use a value ≤ 65535",
                config.compression.min_size,
                u16::MAX,
            );
        }
        Ok(Box::new(ServerPluginWrapper::new(HttpPlugin::new(config))))
    }
}

pub fn folk_plugin_factory() -> Box<dyn PluginFactory> {
    Box::new(HttpPluginFactory)
}