pub struct Authorization { /* private fields */ }
Expand description
Credentials to authenticate a user agent with a server.
§Specifications
§Examples
use http_types::Response;
use http_types::auth::{AuthenticationScheme, Authorization};
let scheme = AuthenticationScheme::Basic;
let credentials = "0xdeadbeef202020";
let authz = Authorization::new(scheme, credentials.into());
let mut res = Response::new(200);
authz.apply(&mut res);
let authz = Authorization::from_headers(res)?.unwrap();
assert_eq!(authz.scheme(), AuthenticationScheme::Basic);
assert_eq!(authz.credentials(), credentials);
Implementations§
Source§impl Authorization
impl Authorization
Sourcepub fn new(scheme: AuthenticationScheme, credentials: String) -> Self
pub fn new(scheme: AuthenticationScheme, credentials: String) -> Self
Create a new instance of Authorization
.
Sourcepub fn from_headers(headers: impl AsRef<Headers>) -> Result<Option<Self>>
pub fn from_headers(headers: impl AsRef<Headers>) -> Result<Option<Self>>
Create a new instance from headers.
Sourcepub fn name(&self) -> HeaderName
pub fn name(&self) -> HeaderName
Get the HeaderName
.
Sourcepub fn value(&self) -> HeaderValue
pub fn value(&self) -> HeaderValue
Get the HeaderValue
.
Sourcepub fn scheme(&self) -> AuthenticationScheme
pub fn scheme(&self) -> AuthenticationScheme
Get the authorization scheme.
Sourcepub fn set_scheme(&mut self, scheme: AuthenticationScheme)
pub fn set_scheme(&mut self, scheme: AuthenticationScheme)
Set the authorization scheme.
Sourcepub fn credentials(&self) -> &str
pub fn credentials(&self) -> &str
Get the authorization credentials.
Sourcepub fn set_credentials(&mut self, credentials: String)
pub fn set_credentials(&mut self, credentials: String)
Set the authorization credentials.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Authorization
impl RefUnwindSafe for Authorization
impl Send for Authorization
impl Sync for Authorization
impl Unpin for Authorization
impl UnwindSafe for Authorization
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more