pub fn body<B: Into<bytes::Bytes>>(mut self, body: Option<B>) -> Request {
        use bytes::Buf;
        use crate::utils::enc::USER_INFO_ENCODE_SET;
        use percent_encoding::{utf8_percent_encode};

        // set cookies
        if let Some(jar) = self.cookies.take() {
            let mut buffer = utils::BytesWriter::new();

            for cook in jar.delta() {
                let name = utf8_percent_encode(cook.name(), USER_INFO_ENCODE_SET);
                let value = utf8_percent_encode(cook.value(), USER_INFO_ENCODE_SET);
                let _ = write!(&mut buffer, "; {}={}", name, value);
            }

            let mut buffer = buffer.into_inner();
            buffer.advance(2);
            let cookie = unsafe { http::header::HeaderValue::from_maybe_shared_unchecked(buffer.freeze()) };

            let _ = self.headers().insert(http::header::COOKIE, cookie);
        }

        let body = body.map(|body| body.into());

        //We automatically insert Content-Length: 0 for empty requests
        //with POST/PUT and removed it otherwise.
        //For everything else we just add Content-Length unless it is already in
        match body.as_ref() {
            None => match self.parts.method {
                hyper::Method::PUT | hyper::Method::POST => match self.parts.headers.entry(http::header::CONTENT_LENGTH) {
                    http::header::Entry::Vacant(value) => {
                        value.insert(utils::content_len_value(0));
                    },
                    _ => (),
                },
                _ => {
                    self.parts.headers.remove(http::header::CONTENT_LENGTH);
                },
            },
            Some(body) => match self.parts.headers.entry(http::header::CONTENT_LENGTH) {
                http::header::Entry::Vacant(value) => {
                    value.insert(utils::content_len_value(body.len() as u64));
                },
                _ => (),
            },
        }

        Request {
            parts: self.parts,
            body,
        }
    }
///Creates request with specified body.
///
///Adds `Content-Length` if not specified by user.
///Following RFC, adds zero length only for `PUT` and `POST` requests
Creates request with specified body.
Adds `Content-Length` if not specified by user.
Following RFC, adds zero length only for `PUT` and `POST` requests
Creates request with specified body . Adds ` Content - Length ` if not specified by user . Following RFC adds zero length only for ` PUT ` and ` POST ` requests
pub fn body<B: Into<bytes::Bytes>>(mut self, body: Option<B>) -> Request {
        use bytes::Buf;
        use crate::utils::enc::USER_INFO_ENCODE_SET;
        use percent_encoding::{utf8_percent_encode};
        // set cookies
        if let Some(jar) = self.cookies.take() {
            let mut buffer = utils::BytesWriter::new();
            for cook in jar.delta() {
                let name = utf8_percent_encode(cook.name(), USER_INFO_ENCODE_SET);
                let value = utf8_percent_encode(cook.value(), USER_INFO_ENCODE_SET);
                let _ = write!(&mut buffer, "; {}={}", name, value);
            }
            let mut buffer = buffer.into_inner();
            buffer.advance(2);
            let cookie = unsafe { http::header::HeaderValue::from_maybe_shared_unchecked(buffer.freeze()) };
            let _ = self.headers().insert(http::header::COOKIE, cookie);
        }
        let body = body.map(|body| body.into());
        //We automatically insert Content-Length: 0 for empty requests
        //with POST/PUT and removed it otherwise.
        //For everything else we just add Content-Length unless it is already in
        match body.as_ref() {
            None => match self.parts.method {
                hyper::Method::PUT | hyper::Method::POST => match self.parts.headers.entry(http::header::CONTENT_LENGTH) {
                    http::header::Entry::Vacant(value) => {
                        value.insert(utils::content_len_value(0));
                    },
                    _ => (),
                },
                _ => {
                    self.parts.headers.remove(http::header::CONTENT_LENGTH);
                },
            },
            Some(body) => match self.parts.headers.entry(http::header::CONTENT_LENGTH) {
                http::header::Entry::Vacant(value) => {
                    value.insert(utils::content_len_value(body.len() as u64));
                },
                _ => (),
            },
        }
        Request {
            parts: self.parts,
            body,
        }
    }
pub fn body < B : Into < bytes :: Bytes > > ( mut self , body : Option < B > ) -> Request { use bytes :: Buf ; use crate :: utils :: enc :: USER_INFO_ENCODE_SET ; use percent_encoding :: { utf8_percent_encode } ; // set cookies if let Some ( jar ) = self . cookies . take ( ) { let mut buffer = utils :: BytesWriter :: new ( ) ; for cook in jar . delta ( ) { let name = utf8_percent_encode ( cook . name ( ) , USER_INFO_ENCODE_SET ) ; let value = utf8_percent_encode ( cook . value ( ) , USER_INFO_ENCODE_SET ) ; let _ = write ! ( mut buffer " " name value ) ; } let mut buffer = buffer . into_inner ( ) ; buffer . advance ( 2 ) ; let cookie = unsafe { http :: header :: HeaderValue :: from_maybe_shared_unchecked ( buffer . freeze ( ) ) } ; let _ = self . headers ( ) . insert ( http :: header :: COOKIE , cookie ) ; } let body = body . map ( | body | body . into ( ) ) ; //We automatically insert Content-Length: 0 for empty requests //with POST/PUT and removed it otherwise. //For everything else we just add Content-Length unless it is already in match body . as_ref ( ) { None => match self . parts . method { hyper :: Method :: PUT | hyper :: Method :: POST => match self . parts . headers . entry ( http :: header :: CONTENT_LENGTH ) { http :: header :: Entry :: Vacant ( value ) => { value . insert ( utils :: content_len_value ( 0 ) ) ; } , _ => ( ) , } , _ => { self . parts . headers . remove ( http :: header :: CONTENT_LENGTH ) ; } , } , Some ( body ) => match self . parts . headers . entry ( http :: header :: CONTENT_LENGTH ) { http :: header :: Entry :: Vacant ( value ) => { value . insert ( utils :: content_len_value ( body . len ( ) as u64 ) ) ; } , _ => ( ) , } , } Request { parts : self . parts , body , } }
Creates request with specified body.
Creates request with specified body .
mut self
body
Option<B>