Commit Graph

16 Commits

Author SHA1 Message Date
Connor McEwen b8ff6212f8 bind this in onreadystatechange call
Summary:
I ran into this problem that `this` is undefined in `onreadystatechange` function calls while using this github api library: https://github.com/michael/github/blob/master/github.js#L72

It seems that in the browser, the `onreadystatechange` function expects `this` to be bound. This example on the xhr spec website can be seen using `this` similarly: https://xhr.spec.whatwg.org/#the-getresponseheader()-method
Closes https://github.com/facebook/react-native/pull/5373

Reviewed By: svcscm

Differential Revision: D2838940

Pulled By: nicklockwood

fb-gh-sync-id: e42184887c7abb0af9c4358a5f33b8c97155624c
2016-01-18 08:55:35 -08:00
Alex Roman 1303e6d039 Implement XHR timeout for Android and IOS natively.
Summary:
Opening this in a separate PR but the discussion can be viewed on #4832.

Basically, this is a native implementation and is a bit more elegant. The consensus on my previous PR was that it should be done natively rather than in JS.

There's now no maximum valid timeout value and a timeout of 0 will never time out.

ontimeout isn't implemented (yet) in this PR.

cc nicklockwood ide philikon
Closes https://github.com/facebook/react-native/pull/5038

Reviewed By: svcscm

Differential Revision: D2838743

Pulled By: nicklockwood

fb-gh-sync-id: 774f864ac35082bf522f7665f4311bd3affbe82c
2016-01-18 08:10:59 -08:00
realaboo b659d7f0d1 Get response url from XMLHttpRequest
Summary:
An HTTP request may be redirected to another URL, sometimes we need to know the URL where the  response comes from.

If the server is in control, we can add an HTTP header X-Request-URL for the redirect URL. However there will be cases that 3rd party services are used.

This PR retrieves the response URL from native networking module and passes to it XMLHttpRequest. The fetch API built on XMLHttpRequest also benefits from this feature.
Closes https://github.com/facebook/react-native/pull/4981

Reviewed By: svcscm

Differential Revision: D2811392

Pulled By: lexs

fb-gh-sync-id: 3ec356fb92f8011b6a243d6879172877a3dc498a
2016-01-07 12:03:48 -08:00
Nick Lockwood 571e646543 Improved null url handling
Summary:
public
Attempting to load an undefined URL via XMLHttpRequest produced a confusing error deep within the network layer. This diff improves the networking stack to catch such errors earlier, and also adds a helpful error in the JS layer.

Fixes https://github.com/facebook/react-native/issues/4558

Reviewed By: javache

Differential Revision: D2811080

fb-gh-sync-id: 1837427e1080a0308f2c4f9a8a42bce2e041fb48
2016-01-07 04:00:38 -08:00
Alexander Blom 532c9112b4 Send HEADERS_RECEIVED and LOADING events on Android
Summary: Send part of the response body every 100 ms if the client has set onreadystatechange. This
is done by using the same events as the iOS code and removing the callback that Android previously
used.

Reconsolidate iOS and Android implementations.

Closes #3772

(The previous commit was reverted)

public

Reviewed By: astreet

Differential Revision: D2658153

fb-gh-sync-id: b1a32d22db7cc2995c673edd31f4bbaf16ca36cb
2015-11-17 06:31:31 -08:00
Nathan Spaun 39ec693866 revert D2631410
Differential Revision: D2655673

fb-gh-sync-id: 115247373767690e63a0d6ce812a578d26b47289
2015-11-13 17:51:30 -08:00
Alexander Blom 4d4c48d32b Send HEADERS_RECEIVED and LOADING events on Android
Summary: Send part of the response body every 100 ms if the client has set onreadystatechange. This
is done by using the same events as the iOS code and removing the callback that Android previously
used.

Reconsolidate iOS and Android implementations.

Closes #3772

public

Reviewed By: mkonicek

Differential Revision: D2647005

fb-gh-sync-id: d006e566867fa47d5f8dff71219cb390bcb8e15a
2015-11-13 07:28:28 -08:00
Jean Regisser 5c01b1e1a0 Fix incorrect lowercase response headers set for XHR responses
Summary:
Trivial change to fix the lowercase response headers set for XHR responses.

What would happen is the first iterated header wouldn't be part of `_lowerCaseResponseHeaders`.
Also it would mutate the original `responseHeaders` object, mixing lowercase headers with the original values.
Closes https://github.com/facebook/react-native/pull/1876
Github Author: Jean Regisser <jean.regisser@gmail.com>
2015-07-07 15:05:45 -08:00
Andy Street 0116abed4f [react_native] JS files from D2164109: [react_native] Fix JS error stacktraces on Android 2015-06-19 04:32:40 -08:00
Nick Lockwood e00b9ac8f3 Added incremental XMLHttpRequest updates
Summary:
@public

Previously, our XMLHttpRequest implementation would only update the readyState when the download was fully completed. This diff adds support for receiving incremental data updates as the download happens, which can be monitored by adding the onreadystatechange event handler.

As a performance optimization, incremental data updates are only sent if the onreadystatechanged handler has been set in the JS, otherwise it just sends the whole data block once download is complete, as before.

Test Plan:
* Run the UIExplorer XMLHttpRequest example (in both OSS and Catalyst) to see incremental downloads working.
* Run the Movies app to see regular (non-incremental) downloads in action
* Run any network-based app in Catalyst shell to verify RKDataManager still works
2015-06-05 15:21:25 -08:00
Philipp von Weitershausen 7069e4cd3f XMLHttpRequest: ignore case for request headers
Summary:
HTTP headers are case-insensitive, so we should treat them that way when they're being set on `XMLHttpRequest`.
Closes https://github.com/facebook/react-native/pull/1381
Github Author: Philipp von Weitershausen <philikon@fb.com>

Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-05-26 08:15:42 -08:00
Philipp von Weitershausen c6ed85afcc new XMLHttpRequest().status is a number, not a string
Summary:
See http://www.w3.org/TR/XMLHttpRequest/#interface-xmlhttprequest
Closes https://github.com/facebook/react-native/pull/1356
Github Author: Philipp von Weitershausen <philikon@fb.com>

Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-05-22 16:42:15 -08:00
Ryan Pastorelle 8a74a9f7c3 Force `responseHeaders` to lower case to respect case-insensitivity
Summary:
`XMLHttpRequest.getResponseHeader` is case-insensitive, therefor the React-Native implementation needs to mimic this behavior as to not break libraries that are dependent on this.

There is a corresponding issue in `superagent` but this is the root cause (https://github.com/visionmedia/superagent/issues/636).
Closes https://github.com/facebook/react-native/pull/1138
Github Author: Ryan Pastorelle <rpastorelle@yahoo.com>

Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-05-05 14:09:40 -08:00
Andy Street eafe93096c [react_native] JS files from D2012956: [react_native] Never return null from XHR.getAllResponseHeaders if request has completed 2015-04-22 09:05:42 -08:00
Josh Zana 368e507b38 Implement XmlHttpRequestBase#getAllResponseHeaders and getResponseHeader
Summary:
Used https://github.com/facebook/react-native/pull/382 as inspiration
but modified to return null instead of undefined as per the spec at
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest

This unblocks use of Dropbox.js within a react-native app, as well
as any other libraries that make use of these methods in XHR usage.

Closes https://github.com/facebook/react-native/issues/872
Closes https://github.com/facebook/react-native/pull/892
Github Author: Josh Zana <joshzana@gmail.com>

Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-04-21 16:45:32 -08:00
Olivia Bishop 40d71e6c5b JS files from D1936817: Add to XMLHttpRequest android and share code with ios 2015-03-24 14:25:20 -08:00