Skip to content

Commit

Permalink
Add fetch's clone function to Request and Response prototypes
Browse files Browse the repository at this point in the history
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.

<img width="601" alt="screen shot 2015-10-22 at 11 50 53 am" src="https://cloud.githubusercontent.com/assets/11564650/10675101/304ebe5a-78b3-11e5-9d6b-24ea6d9fb998.png">

<img width="596" alt="screen shot 2015-10-22 at 12 20 08 pm" src="https://cloud.githubusercontent.com/assets/11564650/10675834/4abaf4ee-78b7-11e5-9d34-436290b64b30.png">
Closes #3614

Reviewed By: svcscm

Differential Revision: D2600517

Pulled By: sahrens

fb-gh-sync-id: d70c5c58e923d997f93bb5aa2d1d90e95d5a75f2
  • Loading branch information
naomiajacobs authored and facebook-github-bot-9 committed Oct 30, 2015
1 parent db71dde commit 854689d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Libraries/Fetch/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ var self = {};
}
this._initBody(body)
}

Request.prototype.clone = function() {
return new Request(this)
}

function decode(body) {
var form = new FormData()
Expand Down Expand Up @@ -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)

Expand Down

1 comment on commit 854689d

@dkoleary88
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.