提交 11f6a0f7 编写于 作者: R Roman Yakubuk

Merge remote-tracking branch 'upstream/master' into CrOrc-fix-resolve-IE-11

...@@ -9,11 +9,3 @@ addons: ...@@ -9,11 +9,3 @@ addons:
cache: cache:
directories: directories:
- node_modules - node_modules
deploy:
provider: npm
email: mislav.marohnic@gmail.com
api_key:
secure: ZEyP/T3jWwvrMp/rdZoMkyc3T7SoFJpGFFCjd7rOG76k/DTRxcYVTAPES8mEq/Xk0fF8qM4ZY//izuxEtFEuJmdRFuvJcIptVrAlbEiqlyNiN1EkwRPayd3qte/UYLvD9bGrfKRVrXeohW0GGDZH48CsHVo3yNrX6NWS7Nxxze4=
on:
tags: true
repo: github/fetch
...@@ -21,6 +21,7 @@ replacement for most uses of XMLHttpRequest in traditional web applications. ...@@ -21,6 +21,7 @@ replacement for most uses of XMLHttpRequest in traditional web applications.
* [Handling HTTP error statuses](#handling-http-error-statuses) * [Handling HTTP error statuses](#handling-http-error-statuses)
* [Sending cookies](#sending-cookies) * [Sending cookies](#sending-cookies)
* [Receiving cookies](#receiving-cookies) * [Receiving cookies](#receiving-cookies)
* [Redirect modes](#redirect-modes)
* [Obtaining the Response URL](#obtaining-the-response-url) * [Obtaining the Response URL](#obtaining-the-response-url)
* [Aborting requests](#aborting-requests) * [Aborting requests](#aborting-requests)
* [Browser Support](#browser-support) * [Browser Support](#browser-support)
...@@ -188,6 +189,10 @@ fetch('/avatars', { ...@@ -188,6 +189,10 @@ fetch('/avatars', {
cookies, always supply the `credentials: 'same-origin'` option instead of cookies, always supply the `credentials: 'same-origin'` option instead of
relying on the default. See [Sending cookies](#sending-cookies). relying on the default. See [Sending cookies](#sending-cookies).
* Not all Fetch standard options are supported in this polyfill. For instance,
[`redirect`](#redirect-modes) and
[`cache`](https://github.github.io/fetch/#caveats) directives are ignored.
#### Handling HTTP error statuses #### Handling HTTP error statuses
To have `fetch` Promise reject on HTTP error statuses, i.e. on any non-2xx To have `fetch` Promise reject on HTTP error statuses, i.e. on any non-2xx
...@@ -229,15 +234,6 @@ fetch('https://example.com:1234/users', { ...@@ -229,15 +234,6 @@ fetch('https://example.com:1234/users', {
}) })
``` ```
To disable sending or receiving cookies for requests to any domain, including
the current one, use the "omit" value:
```javascript
fetch('/users', {
credentials: 'omit'
})
```
The default value for `credentials` is "same-origin". The default value for `credentials` is "same-origin".
The default for `credentials` wasn't always the same, though. The following The default for `credentials` wasn't always the same, though. The following
...@@ -258,6 +254,12 @@ fetch('/users', { ...@@ -258,6 +254,12 @@ fetch('/users', {
}) })
``` ```
Note: due to [limitations of
XMLHttpRequest](https://github.com/github/fetch/pull/56#issuecomment-68835992),
using `credentials: 'omit'` is not respected for same domains in browsers where
this polyfill is active. Cookies will always be sent to same domains in older
browsers.
#### Receiving cookies #### Receiving cookies
As with XMLHttpRequest, the `Set-Cookie` response header returned from the As with XMLHttpRequest, the `Set-Cookie` response header returned from the
...@@ -266,6 +268,15 @@ read with `response.headers.get()`. Instead, it's the browser's responsibility ...@@ -266,6 +268,15 @@ read with `response.headers.get()`. Instead, it's the browser's responsibility
to handle new cookies being set (if applicable to the current URL). Unless they to handle new cookies being set (if applicable to the current URL). Unless they
are HTTP-only, new cookies will be available through `document.cookie`. are HTTP-only, new cookies will be available through `document.cookie`.
#### Redirect modes
The Fetch specification defines these values for [the `redirect`
option](https://fetch.spec.whatwg.org/#concept-request-redirect-mode): "follow"
(the default), "error", and "manual".
Due to limitations of XMLHttpRequest, only the "follow" mode is available in
browsers where this polyfill is active.
#### Obtaining the Response URL #### Obtaining the Response URL
Due to limitations of XMLHttpRequest, the `response.url` value might not be Due to limitations of XMLHttpRequest, the `response.url` value might not be
......
...@@ -44,7 +44,7 @@ function normalizeName(name) { ...@@ -44,7 +44,7 @@ function normalizeName(name) {
if (typeof name !== 'string') { if (typeof name !== 'string') {
name = String(name) name = String(name)
} }
if (/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(name) || name === '') { if (/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(name) || name === '') {
throw new TypeError('Invalid character in header field name') throw new TypeError('Invalid character in header field name')
} }
return name.toLowerCase() return name.toLowerCase()
...@@ -209,6 +209,17 @@ function Body() { ...@@ -209,6 +209,17 @@ function Body() {
this.bodyUsed = false this.bodyUsed = false
this._initBody = function(body) { this._initBody = function(body) {
/*
fetch-mock wraps the Response object in an ES6 Proxy to
provide useful test harness features such as flush. However, on
ES5 browsers without fetch or Proxy support pollyfills must be used;
the proxy-pollyfill is unable to proxy an attribute unless it exists
on the object before the Proxy is created. This change ensures
Response.bodyUsed exists on the instance, while maintaining the
semantic of setting Request.bodyUsed in the constructor before
_initBody is called.
*/
this.bodyUsed = this.bodyUsed
this._bodyInit = body this._bodyInit = body
if (!body) { if (!body) {
this._bodyText = '' this._bodyText = ''
...@@ -391,7 +402,7 @@ export function Response(bodyInit, options) { ...@@ -391,7 +402,7 @@ export function Response(bodyInit, options) {
this.type = 'default' this.type = 'default'
this.status = options.status === undefined ? 200 : options.status this.status = options.status === undefined ? 200 : options.status
this.ok = this.status >= 200 && this.status < 300 this.ok = this.status >= 200 && this.status < 300
this.statusText = 'statusText' in options ? options.statusText : 'OK' this.statusText = 'statusText' in options ? options.statusText : ''
this.headers = new Headers(options.headers) this.headers = new Headers(options.headers)
this.url = options.url || '' this.url = options.url || ''
this._initBody(bodyInit) this._initBody(bodyInit)
...@@ -483,7 +494,15 @@ export function fetch(input, init) { ...@@ -483,7 +494,15 @@ export function fetch(input, init) {
}, 0) }, 0)
} }
xhr.open(request.method, request.url, true) function fixUrl(url) {
try {
return url === '' && self.location.href ? self.location.href : url
} catch (e) {
return url
}
}
xhr.open(request.method, fixUrl(request.url), true)
if (request.credentials === 'include') { if (request.credentials === 'include') {
xhr.withCredentials = true xhr.withCredentials = true
...@@ -491,8 +510,15 @@ export function fetch(input, init) { ...@@ -491,8 +510,15 @@ export function fetch(input, init) {
xhr.withCredentials = false xhr.withCredentials = false
} }
if ('responseType' in xhr && support.blob) { if ('responseType' in xhr) {
xhr.responseType = 'blob' if (support.blob) {
xhr.responseType = 'blob'
} else if (
support.arrayBuffer &&
request.headers.get('Content-Type').indexOf('application/octet-stream') !== -1
) {
xhr.responseType = 'arraybuffer'
}
} }
request.headers.forEach(function(value, name) { request.headers.forEach(function(value, name) {
......
...@@ -123,6 +123,8 @@ exercise.forEach(function(exerciseMode) { ...@@ -123,6 +123,8 @@ exercise.forEach(function(exerciseMode) {
var nativeEdge = /Edge\//.test(navigator.userAgent) && exerciseMode === 'native' var nativeEdge = /Edge\//.test(navigator.userAgent) && exerciseMode === 'native'
var firefox = navigator.userAgent.match(/Firefox\/(\d+)/) var firefox = navigator.userAgent.match(/Firefox\/(\d+)/)
var brokenFF = firefox && firefox[1] <= 56 && exerciseMode === 'native' var brokenFF = firefox && firefox[1] <= 56 && exerciseMode === 'native'
var emptyDefaultStatusText =
exerciseMode !== 'native' || (exerciseMode === 'native' && (Chrome || (firefox && firefox[1] >= 67)))
var polyfillFirefox = firefox && exerciseMode === 'polyfill' var polyfillFirefox = firefox && exerciseMode === 'polyfill'
var omitSafari = var omitSafari =
Safari && exerciseMode === 'native' && navigator.userAgent.match(/Version\/(\d+\.\d+)/)[1] <= '11.1' Safari && exerciseMode === 'native' && navigator.userAgent.match(/Version\/(\d+\.\d+)/)[1] <= '11.1'
...@@ -192,7 +194,10 @@ exercise.forEach(function(exerciseMode) { ...@@ -192,7 +194,10 @@ exercise.forEach(function(exerciseMode) {
assert.equal(headers.get('Content-type'), 'text/html') assert.equal(headers.get('Content-type'), 'text/html')
}) })
test('constructor works with arrays', function() { test('constructor works with arrays', function() {
var array = [['Content-Type', 'text/xml'], ['Breaking-Bad', '<3']] var array = [
['Content-Type', 'text/xml'],
['Breaking-Bad', '<3']
]
var headers = new Headers(array) var headers = new Headers(array)
assert.equal(headers.get('Content-Type'), 'text/xml') assert.equal(headers.get('Content-Type'), 'text/xml')
...@@ -584,19 +589,24 @@ exercise.forEach(function(exerciseMode) { ...@@ -584,19 +589,24 @@ exercise.forEach(function(exerciseMode) {
// https://fetch.spec.whatwg.org/#response-class // https://fetch.spec.whatwg.org/#response-class
suite('Response', function() { suite('Response', function() {
test('default status is 200 OK', function() { featureDependent(test, emptyDefaultStatusText, 'default status is 200', function() {
var res = new Response() var res = new Response()
assert.equal(res.status, 200) assert.equal(res.status, 200)
assert.equal(res.statusText, 'OK') assert.equal(res.statusText, '')
assert.isTrue(res.ok) assert.isTrue(res.ok)
}) })
test('default status is 200 OK when an explicit undefined status code is passed', function() { featureDependent(
var res = new Response('', {status: undefined}) test,
assert.equal(res.status, 200) emptyDefaultStatusText,
assert.equal(res.statusText, 'OK') 'default status is 200 when an explicit undefined status code is passed',
assert.isTrue(res.ok) function() {
}) var res = new Response('', {status: undefined})
assert.equal(res.status, 200)
assert.equal(res.statusText, '')
assert.isTrue(res.ok)
}
)
testBodyExtract(function(body) { testBodyExtract(function(body) {
return new Response(body) return new Response(body)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册