iocaine 3.0.0

The deadliest poison known to AI
Documentation
// SPDX-FileCopyrightText: 2025 Gergely Nagy
// SPDX-FileContributor: Gergely Nagy
//
// SPDX-License-Identifier: MIT

use axum::{
    http::{HeaderMap, StatusCode},
    response::{IntoResponse, Response as AxumResponse},
};

#[derive(Debug, Clone, Default)]
pub struct Response {
    pub status_code: StatusCode,
    pub headers: HeaderMap,
    pub body: Vec<u8>,
}

impl IntoResponse for Response {
    fn into_response(self) -> AxumResponse {
        if self.body.is_empty() {
            (self.status_code, self.headers).into_response()
        } else {
            (self.status_code, self.headers, self.body).into_response()
        }
    }
}

impl Response {
    pub fn minify(&mut self) {
        let cfg = minify_html::Cfg {
            minify_css: true,
            minify_js: false,
            minify_doctype: false,
            ..Default::default()
        };
        self.body = minify_html::minify(self.body.as_slice(), &cfg);
    }
}