leyline-http 0.1.5

HTTP client that impersonates Chrome, Firefox, and Safari on the wire: TLS (JA3/JA4), HTTP/2, and HTTP/3 fingerprints
Documentation
use std::fmt;

use super::{Error, Kind};

#[derive(Debug)]
pub(crate) struct ShutDown;

impl fmt::Display for ShutDown {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str(SHUT_DOWN_MESSAGE)
    }
}

impl std::error::Error for ShutDown {}

#[derive(Debug)]
pub(crate) struct NotProcessed;

impl fmt::Display for NotProcessed {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str("the server did not process the request")
    }
}

impl std::error::Error for NotProcessed {}

const SHUT_DOWN_MESSAGE: &str = "session shut down";

impl Error {
    pub(crate) fn shut_down() -> Error {
        Error::new(Kind::Request)
            .with_message(SHUT_DOWN_MESSAGE)
            .with_source(ShutDown)
    }

    pub fn is_shut_down(&self) -> bool {
        self.source_as::<ShutDown>().is_some()
    }

    pub(crate) fn not_processed(&self) -> bool {
        self.source_as::<NotProcessed>().is_some()
    }
}