feat: Add bearer_auth helper function

Adds a helper function for setting `Bearer`-tokens in `Authorization`
headers.
This commit is contained in:
Vincent Ambo 2019-02-26 16:18:23 +01:00
parent aedfd7c7ac
commit 415e930a07

View file

@ -124,11 +124,18 @@ impl <'a> Request<'a> {
/// Set the `User-Agent` for this request. By default this will be
/// 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)?;
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
/// `Content-Type`.
pub fn body(mut self, content_type: &'a str, data: &'a [u8]) -> Self {