mikeal/request — Issue #88: Possible bug in pipe
Author: jmarca
Created: 2011-10-14 20:16:35+00:00
State: open

I tried to pipe from couchdb to couchdb using request,pipe(), and it failed. CouchDB complained that the content type was wrong.

(My goal is to store view output from multiple couchdbs in a separate db, to rereduce the values from many dbs)

My work around is to GET the view output, then PUT it to couchdb, as follows :

```javascript
var x = request(
{ 'method' : 'GET'
,'uri' : sourcedb+'/'+myview
,'headers' : { 'authorization' : "Basic " + new Buffer(cuser + ":" + cpass).toString('base64')
,'content-type': 'application/json'
}
}
,function(e,r,b){
if(e) handle_err(e,r,b);
request(
{ 'method' : 'PUT'
,'uri' : aggregatedb+'/'+sourcedbid
,'headers' : { 'authorization' : "Basic " + new Buffer(tcuser + ":" + tcpass).toString('base64')
,'content-type': 'application/json'
}
,'body':b
}
,function(e,r,b){
if(e) handle_err(e,r,b);
//console.log(b + ' '+ r)
console.log('done piping reduced view');
callback();
}
)
});
```

It seems one should be able to set up the callback function as a `y` request and then just `x.pipe(y)`, but somewhere the content type is failing to get sent to the second couchdb request