mirror of https://github.com/fafhrd91/actix-web
Added HTTP Authentication for Client
This commit is contained in:
parent
4d17a9afcc
commit
55d95b73c4
|
@ -12,6 +12,7 @@ use serde::Serialize;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use serde_urlencoded;
|
use serde_urlencoded;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
use base64::encode;
|
||||||
|
|
||||||
use super::connector::{ClientConnector, Connection};
|
use super::connector::{ClientConnector, Connection};
|
||||||
use super::pipeline::SendRequest;
|
use super::pipeline::SendRequest;
|
||||||
|
@ -484,6 +485,29 @@ impl ClientRequestBuilder {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set HTTP basic authorization
|
||||||
|
pub fn basic_auth<U, P>(&mut self, username: U, password: Option<P>) -> &mut Self
|
||||||
|
where
|
||||||
|
U: fmt::Display,
|
||||||
|
P: fmt::Display,
|
||||||
|
{
|
||||||
|
let auth = match password {
|
||||||
|
Some(password) => format!("{}:{}", username, password),
|
||||||
|
None => format!("{}", username)
|
||||||
|
};
|
||||||
|
let header_value = format!("Basic {}", encode(&auth));
|
||||||
|
self.header(header::AUTHORIZATION, &*header_value)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set HTTP bearer authentication
|
||||||
|
pub fn bearer_auth<T>( &mut self, token: T) -> &mut Self
|
||||||
|
where
|
||||||
|
T: fmt::Display,
|
||||||
|
{
|
||||||
|
let header_value = format!("Bearer {}", token);
|
||||||
|
self.header(header::AUTHORIZATION, &*header_value)
|
||||||
|
}
|
||||||
|
|
||||||
/// Set content length
|
/// Set content length
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn content_length(&mut self, len: u64) -> &mut Self {
|
pub fn content_length(&mut self, len: u64) -> &mut Self {
|
||||||
|
|
Loading…
Reference in New Issue