From 854689dcfaa7dc13e8ee5dec69f9f7a569595dd1 Mon Sep 17 00:00:00 2001 From: Naomi Jacobs Date: Fri, 30 Oct 2015 10:56:13 -0700 Subject: [PATCH] Add fetch's clone function to Request and Response prototypes Summary: Fetch includes a cloning function that was not included in the React Native fetch.js. This adds it in so that cloning is available on responses from fetch calls in React Native. The code is taken directly from [fetch](https://github.com/github/fetch/blob/master/fetch.js) on Github. screen shot 2015-10-22 at 11 50 53 am screen shot 2015-10-22 at 12 20 08 pm Closes https://github.com/facebook/react-native/pull/3614 Reviewed By: svcscm Differential Revision: D2600517 Pulled By: sahrens fb-gh-sync-id: d70c5c58e923d997f93bb5aa2d1d90e95d5a75f2 --- Libraries/Fetch/fetch.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Libraries/Fetch/fetch.js b/Libraries/Fetch/fetch.js index 68c98a90ddb221..ff5ef29bb7c573 100644 --- a/Libraries/Fetch/fetch.js +++ b/Libraries/Fetch/fetch.js @@ -278,6 +278,10 @@ var self = {}; } this._initBody(body) } + + Request.prototype.clone = function() { + return new Request(this) + } function decode(body) { var form = new FormData() @@ -320,6 +324,15 @@ var self = {}; this.headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers) this.url = options.url || '' } + + Response.prototype.clone = function() { + return new Response(this._bodyInit, { + status: this.status, + statusText: this.statusText, + headers: new Headers(this.headers), + url: this.url + }) + } Body.call(Response.prototype)