rnewson commented on code in PR #314:
URL: https://github.com/apache/couchdb-nano/pull/314#discussion_r2333440923


##########
lib/nano.js:
##########
@@ -251,128 +238,119 @@ module.exports = exports = function dbScope (cfg) {
 
     log({ err: 'couch', body: message, headers: responseHeaders })
 
-    stream.emit('error', error)
+    setTimeout(() => {
+      stream.emit('error', error)
+    }, 10)
   }
 
-  function relax (opts, callback) {
+  function relax (opts) {
     if (typeof opts === 'function') {
-      callback = opts
       opts = { path: '' }
     }
-
     if (typeof opts === 'string') {
       opts = { path: opts }
     }
-
     if (!opts) {
       opts = { path: '' }
-      callback = null
     }
 
-    const qs = Object.assign({}, opts.qs)
+    // the building blocks of the request
+    let body, uri
 
+    // construct headers object to be passed in the request
     const headers = {
-      'content-type': 'application/json',
+      // 'content-type': 'application/json',
       accept: 'application/json',
       'user-agent': `${pkg.name}/${pkg.version} (Node.js ${process.version})`,
       'Accept-Encoding': 'deflate, gzip'
     }
+    Object.assign(headers, cfg.headers ? cfg.headers : {})
+    if (!headers['content-type']) {
+      headers['content-type'] = 'application/json'
+    }
 
-    const req = Object.assign({
-      method: (opts.method || 'GET'),
-      headers,
-      uri: cfg.url
-    }, {
-      ...cfg.requestDefaults,
-      headers: Object.assign(headers, cfg.requestDefaults && 
cfg.requestDefaults.headers ? cfg.requestDefaults.headers : {})
-    })
+    // prevent bugs where people set encoding when piping
+    if (opts.encoding !== undefined) {
+      // req.encoding = opts.encoding
+      delete headers['content-type']
+      delete headers.accept
+    }
 
-    // https://github.com/mikeal/request#requestjar
-    const isJar = opts.jar || cfg.jar || (cfg.requestDefaults && 
cfg.requestDefaults.jar)
+    if (opts.contentType) {
+      headers['content-type'] = opts.contentType
+      delete headers.accept
+    }
 
-    if (opts.signal) {
-      req.signal = opts.signal
+    if (opts.accept) {
+      headers.accept = opts.accept
     }
 
-    if (isJar) {
-      req.withCredentials = true
+    // http://guide.couchdb.org/draft/security.html#cookies
+    if (cfg.cookie) {
+      headers['X-CouchDB-WWW-Authenticate'] = 'Cookie'

Review Comment:
   ???



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to