You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cloning of Headers is trivial -- just call new Headers(this.headers), primitives can be easily cloned as well, the biggest question is how to clone body's Blob or FormData instances and whether it is needed.
It seems that Blob can be cloned by calling blob.slice(blob.size) which returns a new blob. But readBlobAs* functions in polyfill can read same blob multiple times and since blobs are immutable, it should be safe to just pass the same blob as new body.
From what I see in https://developer.mozilla.org/en-US/docs/Web/API/FormData there is no way to get keys/values and iterate through them filling a new FormData instance with values... But based on implementation nuances and lack of ability to actually read FormData I think it's fine to pass the same instance of FormData body too.
The new Response will have bodyUsed = false anyway, so even if source Response has been read already, new one will still be readable...
If you agree with passing non-cloned bodies then I can make a PR in the next few days.
P.S. Method Body.formData() should resolve with a FormData object, not with a text:
Activity
mislav commentedon Jul 31, 2015
Good catch. Care to make a pull request?
kirill-konshin commentedon Jul 31, 2015
Cloning of
Headersis trivial -- just callnew Headers(this.headers), primitives can be easily cloned as well, the biggest question is how to clone body's Blob or FormData instances and whether it is needed.It seems that
Blobcan be cloned by callingblob.slice(blob.size)which returns a new blob. ButreadBlobAs*functions in polyfill can read same blob multiple times and since blobs are immutable, it should be safe to just pass the same blob as new body.From what I see in https://developer.mozilla.org/en-US/docs/Web/API/FormData there is no way to get keys/values and iterate through them filling a new FormData instance with values... But based on implementation nuances and lack of ability to actually read
FormDataI think it's fine to pass the same instance of FormData body too.The new
Responsewill havebodyUsed = falseanyway, so even if sourceResponsehas been read already, new one will still be readable...If you agree with passing non-cloned bodies then I can make a PR in the next few days.
P.S. Method
Body.formData()should resolve with aFormDataobject, not with a text:In polyfill
text()withFormDatabody will throw an exception anyway. I should probably file a separate bug for that.mislav commentedon Jul 31, 2015
Thanks for looking into this. One thing that baffles me is that Chrome's fetch implementation doesn't have the
formData()method for some reason.kirill-konshin commentedon Aug 1, 2015
I suppose that
Body.formData()is not implemented becauseFormDatais totally useless so far. You can write but you cannot read.I'll make a PR.
Fix for JakeChampion#185
kirill-konshin commentedon Sep 29, 2015
After quite a while I finally had time to implement PR: #209
Fix for JakeChampion#185
Fix for JakeChampion#185
Fix for JakeChampion#185