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

http module breaks #71

Closed
nomoreboredom opened this issue Jul 27, 2018 · 8 comments
Closed

http module breaks #71

nomoreboredom opened this issue Jul 27, 2018 · 8 comments

Comments

@nomoreboredom
Copy link

nomoreboredom commented Jul 27, 2018

hi @mvayngrib

Currently i am experiencing a problem. Normally nodeifying was working pretty good, but however after the latest web3-core update, (web3.js 1.0.0-beta.35, see breaking change: The HTTP provider now accepts an options object, instead of timeout and headers parameters:) this line fails on xhr2-cookies:

if (this.withCredentials && (response.headers['set-cookie'] || response.headers['set-cookie2'])) {
  XMLHttpRequest.cookieJar.setCookies(response.headers['set-cookie'] || response.headers['set-cookie2']);
}

and throws Cannot read property 'set-cookie' of undefined.

If I do comment out response.headers['set-cookie'] parts from the node module xhr2-cookies, i do get a ssl error when i try to connect to ethereum rpc node. So this cookie is normally using browser cache I think, whereas we dont have a substitude for that from rn-nodeify. Is this assumption correct, what do you think?

Cheers

@mvayngrib
Copy link
Member

@nomoreboredom thanks for reporting this! Could you poke around in https://github.com/tradle/react-native-http/blob/master/lib/response.js and see why response.headers isn't being defined in your case? (If that's where the response object is coming from. If not, where is it being created?)

@nomoreboredom
Copy link
Author

My app is throwing on this line actually, from xhr2-cookies, xml-http-request.js file line:

if (this.withCredentials && (response.headers['set-cookie'] || response.headers['set-cookie2'])) {
  XMLHttpRequest.cookieJar.setCookies(response.headers['set-cookie'] || response.headers['set-cookie2']);
}

and if I add this check, it stops to throw but I can not build the connection I am supposed to build.

if (this.withCredentials && ((response.headers && response.headers['set-cookie']) || (response.headers && response.headers['set-cookie2']))) {
  XMLHttpRequest.cookieJar.setCookies(response.headers['set-cookie'] || response.headers['set-cookie2']);
}

Hmm actually it may be a web3 bug, as I just noticed this issue: web3/web3.js#1802.

Thanks anyway, will follow that issue and reopen this if it still persists :)

@nomoreboredom
Copy link
Author

So I traced down the issue to this change from web3 lib:

var XHR2 = require('xhr2-cookies').XMLHttpRequest; // jshint ignore: line

It was before just using XMLHttpRequest, whereas it now uses a lib for managing cookies. But as the cookie storage is not per default available for react native, do you think I need to nodeify this using this a package like this, or is it perhaps already done via react-native-http?
https://github.com/joeferraro/react-native-cookies

Thanks!

@nomoreboredom nomoreboredom reopened this Jul 30, 2018
@mvayngrib
Copy link
Member

@nomoreboredom no idea yet :) Can you check why the response is being created without a headers field? That doesn't sound right. And is the response object being created from inside react-native-http or elsewhere?

@0es
Copy link

0es commented Aug 18, 2018

Same issue

@fomenyesu
Copy link

web3 issue . downgrade to v1.0.0-beta.33 solved my problem.

@john-osullivan
Copy link

john-osullivan commented Oct 30, 2018

Running into the same issue, also trying to make web3 work. In my case, Cannot read property 'node' of undefined is throwing out of XMLHttpRequest. Going to see if downgrading fixes things.

EDIT: Maybe, although not quite. I do get a different error, but now it says that it can't connect. Currently trying to get an HTTPProvider to talk to local Ganache from the Android emulator, no dice. Could be related to something else, though.

@mvayngrib
Copy link
Member

closing as web3 issue. If anyone wants to poke around with improving compatibility, happy to reopen

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

5 participants