Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make fetch add a
Content-Type
header based on the type of the body.
Summary: The process of extracting a body from a passed in body object (described here: https://fetch.spec.whatwg.org/#concept-bodyinit-extract) creates both a byte stream and a corresponding `Content-Type` value. These two values are used in the constructor of `Request` and `Response` objects to initialize the body and to set an initial `Content-Type` header. This change makes `Body._initBody()` return the `Content-Type` value corresponding to the type of the object passed in, and to set that header in the corresponding `Request` and `Response` objects that are being constructed. There's a little bit of a dance I need to do in Request to keep track of where the body is coming from, because we're only supposed to be setting the `Content-Type` header if we're getting the body from the options passed in, not if we're copying it from another `Request`. See step 32 of https://fetch.spec.whatwg.org/#dom-request. (This was caught by one of the tests. Yay tests!) I added some corresponding tests to make sure this works. Test Plan: I'm a little bit confused about how to run the tests normally, but this is what I did: - Run `make lint`, see that everything passes - Start up the test server by running `node script/server 3900 &` - Visit http://localhost:3900/test/test.html and http://localhost:3900/test/test-worker.html in Chrome and see that all of the tests pass. From what I can tell, running the tests in Chrome just used the native fetch objects, so to test the polyfill I added `window.fetch = null` in test/test.html before it includes '../fetch.js', and added `self.fetch = null` in test/worker.js before it imports '../fetch.js'. Then: - Visit http://localhost:3900/test/test.html and http://localhost:3900/test/test-worker.html in Chrome and see that all of the tests pass. Reviewers: @jeresig
- Loading branch information