net-cat 0.3.0

Minimal hand-rolled HTTP/1.1 client over std::net::TcpStream. v0.3.0 adds chunked-transfer decoding (`Transfer-Encoding: chunked` responses now yield the correct decoded body) and a redirect follower in `fetch` (RFC 7231 §6.4: 301/302/303 downgrade non-GET/HEAD to GET and drop the body; 307/308 preserve method + body; cross-origin hops strip `Cookie` and `Authorization`; capped at `MAX_REDIRECTS = 10` hops). Optional `tls` feature still wires rustls + webpki-roots for `https://` URLs. No external HTTP crate. 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()
    }
}