use crate::host::{Bytes, handler};
pub struct Body(i32);
impl Body {
pub(crate) fn new(kind: i32) -> Self {
Self(kind)
}
pub fn read(&self) -> Bytes {
Bytes::from(handler::body(self.0))
}
pub fn write(&self, body: &[u8]) {
handler::write_body(self.0, body);
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn body_read_request() {
let body = Body::new(1);
let content = body.read();
assert!(!content.is_empty());
assert!(content.to_str().unwrap().contains("html"));
}
#[test]
fn body_read_response() {
let body = Body::new(0);
let content = body.read();
assert!(content.is_empty());
}
}