pub fn prepare_request<'p, P>(&self, method: &'p P) -> Result<Request, Error>
    where
        P: 'p + Prepare,
    {
        let operation = method.operation();
        let http_method = http_method_for_operation(&operation);
        let uri = build_request_uri(&self.datasource, self.database(), method);
        let mut request = Request::new(http_method, uri);
        request.set_version(HttpVersion::Http11);
        {
            let headers = request.headers_mut();
            headers.set(header_user_agent_for(self.user_agent));
            match *self.datasource.authentication() {
                Authentication::Basic(ref credentials) => headers.set(Authorization(Basic {
                    username: credentials.username().to_owned(),
                    password: Some(credentials.password().to_owned()),
                })),
                Authentication::Jwt(_) => match *self.token.as_ref() {
                    Some(ref token) => headers.set(Authorization(Bearer {
                        token: token.to_owned(),
                    })),
                    None => {
                        return Err(Error::NotAuthenticated(
                            "the client must be authenticated first, \
                             when using JWT authentication"
                                .into(),
                        ));
                    },
                },
                Authentication::None => {},
            }
            for &(ref name, ref value) in method.header().iter() {
                headers.set_raw(name.to_string(), value.to_string());
            }
        }
        if let Some(content) = method.content() {
            let json = serialize_payload(content)?;
            trace!("| request body: {:?}", String::from_utf8(json.clone()));
            request.headers_mut().set(ContentType::json());
            request.headers_mut().set(ContentLength(json.len() as u64));
            request.set_body(json);
        }
        Ok(request)
    }
/// Builds a HTTP-request for a concrete method call and returns it.
Builds a HTTP-request for a concrete method call and returns it.
Builds a HTTP - request for a concrete method call and returns it .
pub fn prepare_request<'p, P>(&self, method: &'p P) -> Result<Request, Error>
    where
        P: 'p + Prepare,
    {
        let operation = method.operation();
        let http_method = http_method_for_operation(&operation);
        let uri = build_request_uri(&self.datasource, self.database(), method);
        let mut request = Request::new(http_method, uri);
        request.set_version(HttpVersion::Http11);
        {
            let headers = request.headers_mut();
            headers.set(header_user_agent_for(self.user_agent));
            match *self.datasource.authentication() {
                Authentication::Basic(ref credentials) => headers.set(Authorization(Basic {
                    username: credentials.username().to_owned(),
                    password: Some(credentials.password().to_owned()),
                })),
                Authentication::Jwt(_) => match *self.token.as_ref() {
                    Some(ref token) => headers.set(Authorization(Bearer {
                        token: token.to_owned(),
                    })),
                    None => {
                        return Err(Error::NotAuthenticated(
                            "the client must be authenticated first, \
                             when using JWT authentication"
                                .into(),
                        ));
                    },
                },
                Authentication::None => {},
            }
            for &(ref name, ref value) in method.header().iter() {
                headers.set_raw(name.to_string(), value.to_string());
            }
        }
        if let Some(content) = method.content() {
            let json = serialize_payload(content)?;
            trace!("| request body: {:?}", String::from_utf8(json.clone()));
            request.headers_mut().set(ContentType::json());
            request.headers_mut().set(ContentLength(json.len() as u64));
            request.set_body(json);
        }
        Ok(request)
    }
pub fn prepare_request < ' p , P > ( & self , method : & ' p P ) -> Result < Request , Error > where P : ' p + Prepare , { let operation = method . operation ( ) ; let http_method = http_method_for_operation ( & operation ) ; let uri = build_request_uri ( & self . datasource , self . database ( ) , method ) ; let mut request = Request :: new ( http_method , uri ) ; request . set_version ( HttpVersion :: Http11 ) ; { let headers = request . headers_mut ( ) ; headers . set ( header_user_agent_for ( self . user_agent ) ) ; match * self . datasource . authentication ( ) { Authentication :: Basic ( ref credentials ) => headers . set ( Authorization ( Basic { username : credentials . username ( ) . to_owned ( ) , password : Some ( credentials . password ( ) . to_owned ( ) ) , } ) ) , Authentication :: Jwt ( _ ) => match * self . token . as_ref ( ) { Some ( ref token ) => headers . set ( Authorization ( Bearer { token : token . to_owned ( ) , } ) ) , None => { return Err ( Error :: NotAuthenticated ( " \
 " . into ( ) , ) ) ; } , } , Authentication :: None => { } , } for & ( ref name , ref value ) in method . header ( ) . iter ( ) { headers . set_raw ( name . to_string ( ) , value . to_string ( ) ) ; } } if let Some ( content ) = method . content ( ) { let json = serialize_payload ( content ) ? ; trace ! ( " " String from_utf8 ( json clone ( ) ) ) ; request . headers_mut ( ) . set ( ContentType :: json ( ) ) ; request . headers_mut ( ) . set ( ContentLength ( json . len ( ) as u64 ) ) ; request . set_body ( json ) ; } Ok ( request ) }
Builds a HTTP-request for a concrete method call and returns it.
Builds a HTTP - request for a concrete method call and returns it .
&self
method
&'p P
&self
method
&'p P