Struct tower_http::auth::AddAuthorizationLayer
source · pub struct AddAuthorizationLayer { /* private fields */ }
Expand description
Layer that applies AddAuthorization
which adds authorization to all requests using the
Authorization
header.
See the module docs for an example.
You can also use SetRequestHeader
if you have a use case that isn’t supported by this
middleware.
Implementations§
source§impl AddAuthorizationLayer
impl AddAuthorizationLayer
sourcepub fn basic(username: &str, password: &str) -> Self
pub fn basic(username: &str, password: &str) -> Self
Authorize requests using a username and password pair.
The Authorization
header will be set to Basic {credentials}
where credentials
is
base64_encode("{username}:{password}")
.
Since the username and password is sent in clear text it is recommended to use HTTPS/TLS with this method. However use of HTTPS/TLS is not enforced by this middleware.
sourcepub fn bearer(token: &str) -> Self
pub fn bearer(token: &str) -> Self
Authorize requests using a “bearer token”. Commonly used for OAuth 2.
The Authorization
header will be set to Bearer {token}
.
§Panics
Panics if the token is not a valid HeaderValue
.
sourcepub fn as_sensitive(self, sensitive: bool) -> Self
pub fn as_sensitive(self, sensitive: bool) -> Self
Mark the header as sensitive.
This can for example be used to hide the header value from logs.
Trait Implementations§
source§impl Clone for AddAuthorizationLayer
impl Clone for AddAuthorizationLayer
source§fn clone(&self) -> AddAuthorizationLayer
fn clone(&self) -> AddAuthorizationLayer
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for AddAuthorizationLayer
impl Debug for AddAuthorizationLayer
Auto Trait Implementations§
impl !Freeze for AddAuthorizationLayer
impl RefUnwindSafe for AddAuthorizationLayer
impl Send for AddAuthorizationLayer
impl Sync for AddAuthorizationLayer
impl Unpin for AddAuthorizationLayer
impl UnwindSafe for AddAuthorizationLayer
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)