net-cat 0.1.0

Minimal hand-rolled HTTP/1.1 client over std::net::TcpStream. Plain HTTP only in v0 (no TLS); used to give web-api-cat's fetch a concrete backend. No external HTTP crate; all parsing and framing are local. No mut beyond the FFI carve-out for TcpStream::read_to_end. Sixth sub-crate of a Servo-replacement webview runtime targeting Tauri.
//! HTTP response.

use crate::headers::Headers;

/// An HTTP response.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Response {
    status: u16,
    reason: String,
    headers: Headers,
    body: Vec<u8>,
}

impl Response {
    /// Build a response.
    #[must_use]
    pub fn new(status: u16, reason: impl Into<String>, headers: Headers, body: Vec<u8>) -> Self {
        Self {
            status,
            reason: reason.into(),
            headers,
            body,
        }
    }

    /// The numeric status code.
    #[must_use]
    pub fn status(&self) -> u16 {
        self.status
    }

    /// The status reason phrase.
    #[must_use]
    pub fn reason(&self) -> &str {
        &self.reason
    }

    /// The response headers.
    #[must_use]
    pub fn headers(&self) -> &Headers {
        &self.headers
    }

    /// The response body bytes.
    #[must_use]
    pub fn body(&self) -> &[u8] {
        &self.body
    }

    /// The body interpreted as UTF-8, falling back to the
    /// lossy-replacement form when invalid sequences are present.
    #[must_use]
    pub fn body_text(&self) -> String {
        String::from_utf8_lossy(&self.body).into_owned()
    }
}