From 368e507b3879231e07b5ee869f688eecc71ea213 Mon Sep 17 00:00:00 2001 From: Josh Zana Date: Tue, 21 Apr 2015 16:43:07 -0700 Subject: [PATCH] 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 Test Plan: Imported from GitHub, without a `Test Plan:` line. --- Libraries/Network/XMLHttpRequestBase.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Libraries/Network/XMLHttpRequestBase.js b/Libraries/Network/XMLHttpRequestBase.js index d7619d075..cfd1e35cc 100644 --- a/Libraries/Network/XMLHttpRequestBase.js +++ b/Libraries/Network/XMLHttpRequestBase.js @@ -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 {