bouillon 0.2.1

A thin, opinionated wrapper around soup that provides an easy, fluent API for sending HTTP requests.
Documentation
use soup::{Message, gio, glib};

/// The request body to be sent with a [`Request`](`crate::Request`).
#[derive(Debug)]
pub struct Body(Inner);

impl Body {
    pub(crate) fn set_as_request_body(&self, message: &Message) {
        match &self.0 {
            Inner::Bytes(bytes) => message.set_request_body_from_bytes(None, Some(bytes)),
            Inner::Stream(input_stream) => message.set_request_body(None, Some(input_stream), -1),
        }
    }
}

impl From<String> for Body {
    fn from(value: String) -> Self {
        value.into_bytes().into()
    }
}

impl From<Vec<u8>> for Body {
    fn from(value: Vec<u8>) -> Self {
        glib::Bytes::from_owned(value).into()
    }
}

impl From<glib::Bytes> for Body {
    fn from(value: glib::Bytes) -> Self {
        Body(Inner::Bytes(value))
    }
}

impl From<gio::InputStream> for Body {
    fn from(value: gio::InputStream) -> Self {
        Body(Inner::Stream(value))
    }
}

#[derive(Debug)]
enum Inner {
    Bytes(glib::Bytes),
    Stream(gio::InputStream),
}