Repository: seanmonstar/reqwest (language: rust)

Issue:
Basic auth shortcut encodes only password, should it encode the whole?
I was looking into sources out of curiosity and spotted curios [thing](https://github.com/seanmonstar/reqwest/blob/master/src/request.rs#L170).

According to [RFC](https://tools.ietf.org/html/rfc7617#section-2) basic auth should form `<username>:<pass>` and be encoded using base64.
Am I missing something or is there alternative scheme for basic auth?
Sorry for stupid question, I'm not well read on HTTP protocol


Discussion / hints:
Yep, looks like that is incorrect. It is supposed to base64 encode the full header value.
oh, ok I'll make PR to correct then

Fix patch:
diff --git a/src/async_impl/request.rs b/src/async_impl/request.rs
index cfbaa4e4c..aeb56b8dd 100644
--- a/src/async_impl/request.rs
+++ b/src/async_impl/request.rs
@@ -123,12 +123,14 @@ impl RequestBuilder {
     /// Enable HTTP basic authentication.
     pub fn basic_auth<U, P>(&mut self, username: U, password: Option<P>) -> &mut RequestBuilder
     where
-        U: Into<String>,
-        P: Into<String>,
+        U: fmt::Display,
+        P: fmt::Display,
     {
-        let username = username.into();
-        let password = password.map(|p| p.into()).unwrap_or(String::new());
-        let header_value = format!("basic {}:{}", username, encode(&password));
+        let auth = match password {
+            Some(password) => format!("{}:{}", username, password),
+            None => format!("{}:", username)
+        };
+        let header_value = format!("basic {}", encode(&auth));
         self.header(::header::AUTHORIZATION, HeaderValue::from_str(header_value.as_str()).expect(""))
     }
 
diff --git a/src/request.rs b/src/request.rs
index d7bac6c3b..8c0489827 100644
--- a/src/request.rs
+++ b/src/request.rs
@@ -162,12 +162,14 @@ impl RequestBuilder {
     /// ```
     pub fn basic_auth<U, P>(&mut self, username: U, password: Option<P>) -> &mut RequestBuilder
     where
-        U: Into<String>,
-        P: Into<String>,
+        U: fmt::Display,
+        P: fmt::Display,
     {
-        let username = username.into();
-        let password = password.map(|p| p.into()).unwrap_or(String::new());
-        let header_value = format!("basic {}:{}", username, encode(&password));
+        let auth = match password {
+            Some(password) => format!("{}:{}", username, password),
+            None => format!("{}:", username)
+        };
+        let header_value = format!("basic {}", encode(&auth));
         self.header(::header::AUTHORIZATION, HeaderValue::from_str(header_value.as_str()).expect(""))
     }
 


Test patch: