feat: Add bearer_auth
helper function
Adds a helper function for setting `Bearer`-tokens in `Authorization` headers.
This commit is contained in:
parent
aedfd7c7ac
commit
415e930a07
1 changed files with 8 additions and 1 deletions
|
@ -124,11 +124,18 @@ impl <'a> Request<'a> {
|
||||||
|
|
||||||
/// Set the `User-Agent` for this request. By default this will be
|
/// Set the `User-Agent` for this request. By default this will be
|
||||||
/// set to cURL's standard user agent.
|
/// set to cURL's standard user agent.
|
||||||
pub fn user_agent<'b: 'a>(mut self, agent: &str) -> Result<Self, curl::Error> {
|
pub fn user_agent(mut self, agent: &str) -> Result<Self, curl::Error> {
|
||||||
self.handle.useragent(agent)?;
|
self.handle.useragent(agent)?;
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set the `Authorization` header to a `Bearer` value with the
|
||||||
|
/// supplied token.
|
||||||
|
pub fn bearer_auth(mut self, token: &str) -> Result<Self, curl::Error> {
|
||||||
|
self.headers.append(&format!("Authorization: Bearer {}", token))?;
|
||||||
|
Ok(self)
|
||||||
|
}
|
||||||
|
|
||||||
/// Add a byte-array body to a request using the specified
|
/// Add a byte-array body to a request using the specified
|
||||||
/// `Content-Type`.
|
/// `Content-Type`.
|
||||||
pub fn body(mut self, content_type: &'a str, data: &'a [u8]) -> Self {
|
pub fn body(mut self, content_type: &'a str, data: &'a [u8]) -> Self {
|
||||||
|
|
Loading…
Reference in a new issue