Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

db.streamChanges() seems broke #5

Closed
zdzolton opened this issue Mar 26, 2010 · 4 comments
Closed

db.streamChanges() seems broke #5

zdzolton opened this issue Mar 26, 2010 · 4 comments

Comments

@zdzolton
Copy link
Contributor

Calling db.streamChanges() generates a URL including this:
/_changes?feed=%22continuous%22

When it should be this:
/_changes?feed=continuous

@zdzolton
Copy link
Contributor Author

After a small amount of digging, I noticed that this wasn't working because streamChanges() sends its options through the toQuery() function, which JSON encodes the feed param.

Given that AFAIK the only JSON-valued parameters in CouchDB's API are key, startkey and endkey, I think you should instead whitelist the params to be JSON encoded:

function(query) {
for (var k in query) {
if (['key', 'startkey', 'endkey'].indexOf(k) != -1) {
query[k] = JSON.stringify(query[k]);
} else {
query[k] = String(query[k]);
}
}
return querystring.stringify(query);
}

I think this should cover your bases:
node> toQuery({ limit: 5, include_docs: true, key: { foo: "bar" }, stale: "ok" });
'limit=5&include_docs=true&key=%7B%22foo%22%3A%22bar%22%7D&stale=ok'

@felixge
Copy link
Owner

felixge commented Apr 1, 2010

Did this actually cause you any issues?

I ask because one of the couchdb guys told me all query values should be JSON quoted other than "stale=ok".

@zdzolton
Copy link
Contributor Author

zdzolton commented Apr 1, 2010

This definitely wasn't working for me. Any value of feed besides continuous (w/o quotes) closes the HTTP connection immediately.

I've been writing code against my own branch just fine, with the parameter encoding patch described above. You should have a pull request waiting from me... (^_^)

@felixge
Copy link
Owner

felixge commented Apr 7, 2010

Thanks! Applied in d43a67a

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants