You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was under the impression that @Tryneus fixed the content type issues in r.http and you can insert binary data via r.http into documents. It's possible that r.binary(r.http) doesn't work, but I think there is a different way of doing it.
@Tryneus -- could you comment on this? Should we make r.binary(r.http) work explicitly? (I think we should)
And you may skip the resultFormat optarg in most of the cases.
r.binary is just a client term that convert a buffer to an object like {$reql_type$: "BINARY", data: <base64string>} and will not accept anything else than a buffer.
r.binary(r.http()) will now work. Keep in mind that if the HTTP response is interpreted as a string but contains NUL characters, it will still error. The only way around that is to use result_format=binary.
We should try very hard not to encourage people ro write r.binary(r.http()). It will appear to work until there's a NULL character, or a future version of RethinkDB actually checks for UTF-8, but then it will just blow up.
Can't you just rewrite the term on the server from r.binary(r.http()) to r.http(..., result_format='binary') ? Seems like that's the abstraction
people would be hoping for when wrapping it like that
On Mon, Aug 18, 2014 at 7:00 PM, Michael Lucy [email protected]
wrote:
We should try very hard not to encourage people ro write
r.binary(r.http()). It will appear to work until there's a NULL
character, or a future version of RethinkDB actually checks for UTF-8, but
then it will just blow up.
—
Reply to this email directly or view it on GitHub #467 (comment).
@deontologician, I'm not aware of any way we can do look-ahead like that in the query-language. @mlucy, any ideas? Would we perhaps be able to use eval_flags_t for this?
@deontologician: if you mean "is it technically feasible", then the answer is yes, but it would be bad because that's not how our type system works in general. We'd have to hard-code that combination, and it would be extremely confusing because r.binary(r.http()) would work but e.g. r.binary("PREFIX" + r.http()) still wouldn't. (In general, having the return type of a term depend on the term calling it seems confusing to me.)
@Tryneus: If we did want to do this, we'd probably do it at compile-time in binary_term_ts constructor (we'd look at the source code for its arguments and add the binary optarg to http calls). eval_flags_t is evil and needs to die.
Well, if you're using result_format='auto', your return type could randomly change in any situation, and at least wrapping it in r.binary would force it to be consistent or error. Not that I think it's a perfectly good solution, but it might be better than the current situation.
@Tryneus: how do we currently detect the result format when it's set to auto? Detecting based on the content-type seems very different from detecting based on the presence or absence of a null byte.
@deontologician: I don't quite follow. If the content-type says it's binary data, shouldn't we just return binary data? Do we not currently do that?
OK, so my confusion was when it would blow up. @mlucy explained that it
wouldn't make it out of the r.http call if there was a nul, I was thinking
it would make it out and would blow up somewhere else down the line, which
would be avoided if the very next thing was converting it to a binary.
What if r.http validates against utf-8 for real (rather than just nul
checking) and then returns a binary if that fails? It's unlikely that a
random binary file happens to be utf-8 valid (I would guess for all but the
shortest strings, effectively impossible).
Ideally we would validate all strings like that, but we currently don't and haven't ever done that, and I think it would be very unexpected behavior to only validate strings that arrive from r.http and nowhere else. We also can't change it anywhere else without potentially breaking users' applications, so that kind of a change would need to be in a new major version of the query language (e.g. 2.0).
Well, actually, now that I think about it, it seems like this is a general
issue with r.http. If a page doesn't get automatically detected as binary,
and happens to contain a nul character, it's going to blow up anyway,
regardless of whether the enclosing term is r.binary or not.
As to string validation everywhere vs. just in r.http, I think it makes
sense since outside data is dirty. There is always the possibility of some
application/X-Foo content-type that runs the risk of having a nul
character in it. In light of that, I'd say it makes sense to do heavier
validation, or switch the default result type to be binary instead of string
to clarify: I think it's justifiable to only have the validation in r.http, since that's kind of like a gatekeeper of sorts pulling
potentially dirty data into the database.
@deontologician, does that mean you support my suggestion to have r.http produce a binary object when result_format='auto' and creating a string fails? (Note: this should only happen for invalid JSON-P and unrecognized Content-Types from the above list)
@mlucy, it doesn't seem that having result_format='auto' work in this way is much different than how we handle JSON-P.
I'm taking this out of the 1.14 docs milestone because I don't think it should be a release blocker. (The docs for r.binary itself with examples are already there, and the article's written and in review. And doesn't use r.binary(r.http()) in it!)
@Tryneus yes, but I think creating the string should be subject to utf-8 validation, rather than just checking for nul bytes. It may be that this is a big performance hit, in which case it's probably safer to default to returning a binary unless we recognize the content-type as explicitly not binary.
Activity
coffeemug commentedon Aug 18, 2014
Note, it would be very cool if we had two examples:
r.http(e.g. a gravatar icon)neumino commentedon Aug 18, 2014
r.binary(r.http(...))doesn't actually work.r.binaryonly accepts a Buffer (or similar things in Python/Ruby).chipotle commentedon Aug 18, 2014
If you use r.http('http://www.gravatar.com/avatar/18b515cae379d4333296db7121b80458', result_format='binary'), that's supposed to return a binary object directly, right? So you wouldn't need the r.binary() wrapper around it -- you'd just use the binary result_format argument. Or is this incorrect?
coffeemug commentedon Aug 18, 2014
I was under the impression that @Tryneus fixed the content type issues in
r.httpand you can insert binary data viar.httpinto documents. It's possible thatr.binary(r.http)doesn't work, but I think there is a different way of doing it.@Tryneus -- could you comment on this? Should we make
r.binary(r.http)work explicitly? (I think we should)neumino commentedon Aug 18, 2014
Yep, like @chipotle said, you basically just do
And you may skip the
resultFormatoptarg in most of the cases.r.binaryis just a client term that convert a buffer to an object like{$reql_type$: "BINARY", data: <base64string>}and will not accept anything else than a buffer.coffeemug commentedon Aug 18, 2014
I think we should allow
r.binary(r.http())to avoid confusing users. Let's wait until @Tryneus chimes in.Tryneus commentedon Aug 18, 2014
Opened rethinkdb/rethinkdb#2931 for adding
r.binaryon the server. For the most part it's just another way of writingcoerce_to('binary').Tryneus commentedon Aug 19, 2014
r.binary(r.http())will now work. Keep in mind that if the HTTP response is interpreted as a string but contains NUL characters, it will still error. The only way around that is to useresult_format=binary.mlucy commentedon Aug 19, 2014
We should try very hard not to encourage people ro write
r.binary(r.http()). It will appear to work until there's a NULL character, or a future version of RethinkDB actually checks for UTF-8, but then it will just blow up.deontologician commentedon Aug 19, 2014
Can't you just rewrite the term on the server from
r.binary(r.http())tor.http(..., result_format='binary')? Seems like that's the abstractionpeople would be hoping for when wrapping it like that
On Mon, Aug 18, 2014 at 7:00 PM, Michael Lucy [email protected]
wrote:
Tryneus commentedon Aug 19, 2014
@deontologician, I'm not aware of any way we can do look-ahead like that in the query-language. @mlucy, any ideas? Would we perhaps be able to use
eval_flags_tfor this?mlucy commentedon Aug 19, 2014
@deontologician: if you mean "is it technically feasible", then the answer is yes, but it would be bad because that's not how our type system works in general. We'd have to hard-code that combination, and it would be extremely confusing because
r.binary(r.http())would work but e.g.r.binary("PREFIX" + r.http())still wouldn't. (In general, having the return type of a term depend on the term calling it seems confusing to me.)mlucy commentedon Aug 19, 2014
@Tryneus: If we did want to do this, we'd probably do it at compile-time in
binary_term_ts constructor (we'd look at the source code for its arguments and add thebinaryoptarg tohttpcalls).eval_flags_tis evil and needs to die.4 remaining items
Tryneus commentedon Aug 19, 2014
Well, if you're using
result_format='auto', your return type could randomly change in any situation, and at least wrapping it inr.binarywould force it to be consistent or error. Not that I think it's a perfectly good solution, but it might be better than the current situation.mlucy commentedon Aug 19, 2014
@Tryneus: how do we currently detect the result format when it's set to
auto? Detecting based on the content-type seems very different from detecting based on the presence or absence of a null byte.@deontologician: I don't quite follow. If the content-type says it's binary data, shouldn't we just return binary data? Do we not currently do that?
Tryneus commentedon Aug 19, 2014
The
r.httpcommand currently uses theContent-Typeof the response if and only ifresult_format='auto':application/json- Parse as JSONapplication/json-p,text/javascript,text/json-p- Try a few things in order:audio/*,image/*,video/*,application/octet-stream- Binarydeontologician commentedon Aug 20, 2014
OK, so my confusion was when it would blow up. @mlucy explained that it
wouldn't make it out of the r.http call if there was a nul, I was thinking
it would make it out and would blow up somewhere else down the line, which
would be avoided if the very next thing was converting it to a binary.
What if r.http validates against utf-8 for real (rather than just nul
checking) and then returns a binary if that fails? It's unlikely that a
random binary file happens to be utf-8 valid (I would guess for all but the
shortest strings, effectively impossible).
On Tue, Aug 19, 2014 at 4:19 PM, Tryneus [email protected] wrote:
Tryneus commentedon Aug 20, 2014
Ideally we would validate all strings like that, but we currently don't and haven't ever done that, and I think it would be very unexpected behavior to only validate strings that arrive from
r.httpand nowhere else. We also can't change it anywhere else without potentially breaking users' applications, so that kind of a change would need to be in a new major version of the query language (e.g. 2.0).mlucy commentedon Aug 20, 2014
If we have code to validate UTF-8 strings, we should probably just use it everywhere.
deontologician commentedon Aug 20, 2014
Well, actually, now that I think about it, it seems like this is a general
issue with r.http. If a page doesn't get automatically detected as binary,
and happens to contain a nul character, it's going to blow up anyway,
regardless of whether the enclosing term is r.binary or not.
As to string validation everywhere vs. just in r.http, I think it makes
sense since outside data is dirty. There is always the possibility of some
application/X-Foo content-type that runs the risk of having a nul
character in it. In light of that, I'd say it makes sense to do heavier
validation, or switch the default result type to be binary instead of string
deontologician commentedon Aug 20, 2014
to clarify: I think it's justifiable to only have the validation in
r.http, since that's kind of like a gatekeeper of sorts pullingpotentially dirty data into the database.
Tryneus commentedon Aug 20, 2014
@deontologician, does that mean you support my suggestion to have
r.httpproduce a binary object whenresult_format='auto'and creating a string fails? (Note: this should only happen for invalid JSON-P and unrecognizedContent-Types from the above list)@mlucy, it doesn't seem that having
result_format='auto'work in this way is much different than how we handle JSON-P.chipotle commentedon Aug 20, 2014
I'm taking this out of the 1.14 docs milestone because I don't think it should be a release blocker. (The docs for
r.binaryitself with examples are already there, and the article's written and in review. And doesn't user.binary(r.http())in it!)deontologician commentedon Aug 20, 2014
@Tryneus yes, but I think creating the string should be subject to utf-8 validation, rather than just checking for nul bytes. It may be that this is a big performance hit, in which case it's probably safer to default to returning a binary unless we recognize the content-type as explicitly not binary.
deontologician commentedon Aug 20, 2014
Also @chipotle, sorry for hijacking this docs thread. It probably needs to be its own issue
mlucy commentedon Aug 20, 2014
This should probably be an issue in the main
rethinkdbissue tracker taggedRQL_proposal. We can discuss it during the upcoming discussion period.