[fetch] Add a way to copy Requests with a different URL (#191)

Currently, once a `Request` is created, there are easy ways to create new `Request`s which are copies of the original with modified properties, using the `new Request(oldRequest, { /* changed attributes */ })` usage of the constructor. However, there doesn't appear to be an easy way to create a copy of the `Request` with a different URL.

I asked a question on Stack Overflow to this effect: http://stackoverflow.com/questions/34640286/how-do-i-copy-a-request-object-with-a-different-url

The best answer manually copies all of the attributes out of the old `Request` object, taking special care to copy over the body. However, this implementation very cumbersome and still causes issues:
 - It is not synchronous
 - If the original `Request` doesn't have a `Content-Type` header, the body isn't copied
 - We lose the actual type of the body, as it is turned into a `Blob` regardless of the original type (this might not actually be a problem related fetch itself, but is annoying when using a polyfill, because converting the body to `Blob`s results in the request sent being different).

Would it be possible to add an option to the constructor which allows for a copy with a different URL?

Some possible implementations might be:
 - Allowing a `url` member in the `init` object of the `Request` constructor. E.g. `new Request(oldRequest, { url: "/new-url" })`
 - Make passing a `Request` into the second argument of the constructor copy the data out of that argument. E.g. `new Request("/new-url", oldRequest)`

---
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/191

Received on Thursday, 7 January 2016 20:33:48 UTC