about summary refs log tree commit diff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2019-02-26T15·18+0100
committerVincent Ambo <mail@tazj.in>2019-02-26T16·30+0100
commit415e930a07d8c3ae481a2c9e9efc0f1ea938bd5f (patch)
treec4c9f7729d68291e4df03837f0f37704181e3cdc /src/lib.rs
parentaedfd7c7acb0fb49699bd4bcd4b5919e14bb0407 (diff)
feat: Add `bearer_auth` helper function
Adds a helper function for setting `Bearer`-tokens in `Authorization`
headers.
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 027a8cda5b93..56d6327e40bf 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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 {