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

Additional options to r.http #39

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

marshall007
Copy link

See #36. Still not the complete list, but this adds support for:

  • resultFormat
  • timeout (needs test)
  • redirects (needs test)
  • header
  • params

There are currently three failing test cases. I think this is because Query::evaluate is stripping out all the options passed to r.http. I haven't had time to figure out why that's the case and I'm also not sure whether I should expect options or internalOptions to be populated with the user-supplied options. Let me know and I'll update this PR.

The reason I don't have tests for timeout and redirects is because (AFAIK) there's no way to emulate that with httpbin.

@neumino
Copy link
Owner

neumino commented Jun 25, 2015

Thanks @marshall007, I've been quite busy these past weeks and didn't have much time to work on reqlite, so I really appreciate your help :)

What you probably want to populate is options. internalOptions is currently only used to track if a query is atomic (for writes).
For example for update, we set deterministic: true.
https://github.com/neumino/reqlite/blob/master/lib/document.js#L36

Let me know if you have more questions.
For timeout/redirects, it's fine if there are no tests. If you can manually check it, it's cool, else we'll just pay attention when merging :)

@marshall007
Copy link
Author

No problem! One other thing: when I call r.http(..., { header: [ 'User-Agent: ...' ] }) from the tests, the options passed to me are { header: [ 2, [ 'User-Agent: ...' ] ] }. Is this a bug?

@neumino
Copy link
Owner

neumino commented Jun 25, 2015

@marshall007 -- arrays are represented with the MAKE_ARRAY from the proto-def.js file:

[2, [x1, x2, ...]]

If you want it as [x1, x2, ...], you can call util.toDatum(<value>)

@marshall007
Copy link
Author

@neumino if I call util.toDatum([ 2, [ 'User-Agent: ...' ] ]) I just get back a copy of the array.

Could you explain what Query.prototype.evaluate is doing and why some terms call it with args[0] and others pass their options argument?

@neumino
Copy link
Owner

neumino commented Jun 26, 2015

Sure, first sorry for the lack of comments/doc. I'll try to improve that.

Then basically Query.prototype.evaluate evaluates a term. Baring primitives, terms are what the JSON object that the drivers build.

For example [2, ["foo", "bar"] is r.expr(["foo", "bar"]) and where 2 is MAKE_ARRAY. We basically carry terms everywhere and evaluates them (to datum) only when we need.

In the case of r.http and its options, we can have:

r.http("www.example.com", { timeout: 200})

In this case it's trivial to evaluate the options, it's {timeout: 200}. The reason why we need to evaluate the options is because this is allowed:

r.http("www.example.com", { timeout: r.random()})
// or
r.http("www.example.com", { timeout: r.table('constant').get('httptimeout')('value')})

timeout: internalOptions.timeout || 30000,
maxRedirects: internalOptions.redirects || 1,
qs: internalOptions.params,
headers: httpUtil.headers(internalOptions.header)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you want options.header

@neumino
Copy link
Owner

neumino commented Jun 26, 2015

Added a few comments in your commits, hopefully it make things more clear. Let me know if you have more questions.

@neumino
Copy link
Owner

neumino commented Jun 26, 2015

Oh also self.evaluate(args[0], internalOptions) means that we are going to evaluate the first argument of a given method.
self.evalute(options, internalOptions) means that we are going to evaluate the options of the given method.

So for example for r.random(3, 4, {float: true}), args is [3, 4] and options is {float: true}

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

Successfully merging this pull request may close these issues.

2 participants