pub struct Authorization { /* private fields */ }
Expand description
Credentials to authenticate a user agent with a server.
§Specifications
§Examples
use http_types_rs::Response;
use http_types_rs::auth::{AuthenticationScheme, Authorization};
let scheme = AuthenticationScheme::Basic;
let credentials = "0xdeadbeef202020";
let authz = Authorization::new(scheme, credentials.into());
let mut res = Response::new(200);
res.insert_header(&authz, &authz);
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 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§
Source§impl Debug for Authorization
impl Debug for Authorization
Source§impl Header for Authorization
impl Header for Authorization
Source§fn header_name(&self) -> HeaderName
fn header_name(&self) -> HeaderName
Access the header’s name.
Source§fn header_value(&self) -> HeaderValue
fn header_value(&self) -> HeaderValue
Access the header’s value.
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
Source§impl<T> ToHeaderValues for Twhere
T: Header,
impl<T> ToHeaderValues for Twhere
T: Header,
Source§type Iter = IntoIter<HeaderValue>
type Iter = IntoIter<HeaderValue>
Returned iterator over header values which this type may correspond to.
Source§fn to_header_values(&self) -> Result<<T as ToHeaderValues>::Iter, Error>
fn to_header_values(&self) -> Result<<T as ToHeaderValues>::Iter, Error>
Converts this object to an iterator of resolved
HeaderValues
.