Merge pull request #247 from jandrieu/master

fixed content_type mistake in insertMultipart
diff --git a/README.md b/README.md
index 1b38038..37d6c69 100644
--- a/README.md
+++ b/README.md
@@ -165,6 +165,18 @@
 ```
 Please check [request] for more information on the defaults. They support features like cookie jar, proxies, ssl, etc.
 
+You can tell nano to not parse the url (maybe the server is behind a proxy, is accessed through a rewrite rule or other):
+
+```js
+// nano does not parse the url and return the server api
+// "http://localhost:5984/prefix" is the CouchDB server root
+var couch = require('nano')(
+  { "url"      : "http://localhost:5984/prefix"
+    "parseUrl" : false
+  });
+var db = couch.use('foo')
+```
+
 ### pool size and open sockets
 
 a very important configuration parameter if you have a high traffic website and are using nano is setting up the `pool.size`. by default, the node.js http global agent (client) has a certain size of active connections that can run simultaneously, while others are kept in a queue. pooling can be disabled by setting the `agent` property in `requestDefaults` to false, or adjust the global pool size using:
@@ -321,7 +333,7 @@
   `opts.att`
 * `opts.doc` – the document name
 * `opts.att` – the attachment name
-* `opts.params` – query string parameters, appended after any existing `opts.path`, `opts.doc`, or `opts.att`
+* `opts.qs` – query string parameters, appended after any existing `opts.path`, `opts.doc`, or `opts.att`
 * `opts.content_type` – the content type of the request, default to `json`
 * `opts.headers` – additional http headers, overrides existing ones
 * `opts.body` – the document or attachment body
@@ -726,7 +738,7 @@
   }
 
   console.log('user is %s and has these roles: %j',
-    session.userCtx.user, session.userCtx.roles);
+    session.userCtx.name, session.userCtx.roles);
 });
 ```
 
diff --git a/lib/nano.js b/lib/nano.js
index 28942fd..6d4b1e9 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -31,6 +31,23 @@
     request.defaults(cfg.requestDefaults);
   var followAgent = (typeof cfg.follow === 'function') ? cfg.follow : follow;
   var log = typeof cfg.log === 'function' ? cfg.log : logger(cfg);
+  var parseUrl = 'parseUrl' in cfg ? cfg.parseUrl : true;
+
+  function maybeExtractDatabaseComponent() {
+    if (!parseUrl) {
+      return;
+    }
+
+    var path = u.parse(cfg.url);
+    var pathArray = path.pathname.split('/').filter(function(e) { return e; });
+    var db = pathArray.pop();
+    var rootPath = path.pathname.replace(/\/?$/, '/..');
+
+    if (db) {
+      cfg.url = u.resolve(cfg.url, rootPath).replace(/\/?$/, '');
+      return db;
+    }
+  }
 
   function relax(opts, callback) {
     if (typeof opts === 'function') {
@@ -716,17 +733,9 @@
     followUpdates: followUpdates
   });
 
-  var path = u.parse(cfg.url);
-  var pathArray = path.pathname.split('/').filter(function(e) { return e; });
-  var db = pathArray.pop();
-  var rootPath = path.pathname.replace(/\/?$/, '/..');
+  var db = maybeExtractDatabaseComponent();
 
-  if (db) {
-    cfg.url = u.resolve(cfg.url, rootPath).replace(/\/?$/, '');
-    return docModule(db);
-  }
-
-  return serverScope;
+  return db ? docModule(db) : serverScope;
 };
 
 /*
diff --git a/package.json b/package.json
index 3d89117..e28f7ee 100644
--- a/package.json
+++ b/package.json
@@ -4,7 +4,7 @@
   "license": "apache 2.0",
   "homepage": "http://github.com/dscape/nano",
   "repository": "git://github.com/dscape/nano",
-  "version": "6.0.2",
+  "version": "6.1.0",
   "author": "Nuno Job <nunojobpinto@gmail.com> (http://nunojob.com)",
   "keywords": [
     "couchdb",
@@ -18,7 +18,7 @@
   ],
   "dependencies": {
     "request": "2.46.0",
-    "follow": "^0.11.3",
+    "follow": "^0.11.4",
     "errs": "^0.3.0",
     "underscore": "^1.7.0",
     "debug": "^2.0.0"
diff --git a/tests/integration/shared/config.js b/tests/integration/shared/config.js
index 43c1cff..23ffd8b 100644
--- a/tests/integration/shared/config.js
+++ b/tests/integration/shared/config.js
@@ -77,6 +77,20 @@
   assert.end();
 });
 
+it('should not parse urls when parseURL flag set to false', function(assert) {
+  var url = 'http://someurl.com/path';
+
+  assert.equal(
+    Nano({
+      url: url,
+      parseUrl: false
+    }).config.url,
+    url,
+    'the untouched url');
+
+  assert.end();
+});
+
 it('should accept and handle customer http headers', function(assert) {
   var nanoWithDefaultHeaders = Nano({
     url: helpers.couch,