couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gar...@apache.org
Subject [1/3] fauxton commit: updated refs/heads/master to 367d422
Date Mon, 20 Feb 2017 18:03:19 GMT
Repository: couchdb-fauxton
Updated Branches:
  refs/heads/master 787280b08 -> 367d42268


don't encode username/pass unless necessary


Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/a6af114a
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/a6af114a
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/a6af114a

Branch: refs/heads/master
Commit: a6af114a466a1d68c84822b2cb0f9fd7bc42993a
Parents: 787280b
Author: Nolan Lawson <nolan.lawson@gmail.com>
Authored: Sat Feb 18 08:01:31 2017 -0800
Committer: Garren Smith <garren.smith@gmail.com>
Committed: Mon Feb 20 20:02:48 2017 +0200

----------------------------------------------------------------------
 app/addons/replication/api.js | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/a6af114a/app/addons/replication/api.js
----------------------------------------------------------------------
diff --git a/app/addons/replication/api.js b/app/addons/replication/api.js
index e5ccce0..7d5b40b 100644
--- a/app/addons/replication/api.js
+++ b/app/addons/replication/api.js
@@ -40,6 +40,9 @@ export const getUsername = () => {
 };
 
 export const getAuthHeaders = (username, password) => {
+  if (!username || !password) {
+    return {};
+  }
   return {
     'Authorization': 'Basic ' + base64.encode(username + ':' + password)
   };
@@ -61,10 +64,17 @@ export const getTarget = ({replicationTarget, localTarget, remoteTarget,
replica
   const encodedLocalTarget = encodeURIComponent(localTarget);
   const headers = getAuthHeaders(username, password);
 
+  const {
+    origin,
+    port,
+    protocol,
+    hostname
+  } = window.location;
+
   if (replicationTarget === Constants.REPLICATION_TARGET.EXISTING_LOCAL_DATABASE) {
     target = {
       headers: headers,
-      url: `${window.location.origin}/${encodedLocalTarget}`
+      url: `${origin}/${encodedLocalTarget}`
     };
   } else if (replicationTarget === Constants.REPLICATION_TARGET.NEW_LOCAL_DATABASE) {
 
@@ -72,11 +82,12 @@ export const getTarget = ({replicationTarget, localTarget, remoteTarget,
replica
     if (replicationSource === Constants.REPLICATION_SOURCE.LOCAL) {
       target = {
         headers: headers,
-        url: `${window.location.origin}/${encodedLocalTarget}`
+        url: `${origin}/${encodedLocalTarget}`
       };
     } else {
-      const port = window.location.port === '' ? '' : ':' + window.location.port;
-      target = `${window.location.protocol}//${username}:${password}@${window.location.hostname}${port}/${encodedLocalTarget}`;
+      target = `${protocol}//` +
+        ((username && password) ? `${username}:${password}@` : '') +
+        `${hostname}${port ? `:${port}` : ''}/${encodedLocalTarget}`;
     }
   }
 


Mime
View raw message