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.
This commit is contained in:
Josh Zana 2015-04-21 16:43:07 -07:00
parent 17e5b04d1a
commit 368e507b38
1 changed files with 13 additions and 4 deletions

View File

@ -53,13 +53,22 @@ class XMLHttpRequestBase {
}
getAllResponseHeaders(): ?string {
/* Stub */
return '';
if (this.responseHeaders) {
var headers = [];
for (var headerName in this.responseHeaders) {
headers.push(headerName + ': ' + this.responseHeaders[headerName]);
}
return headers.join('\n');
}
return null;
}
getResponseHeader(header: string): ?string {
/* Stub */
return '';
if (this.responseHeaders) {
var value = this.responseHeaders[header];
return value !== undefined ? value : null;
}
return null;
}
setRequestHeader(header: string, value: any): void {