forked from jpillora/xhook
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements null body for specific status codes per HTTP spec.
- Null body is now used for status codes 101, 204, 205, and 304. - See jpillora#116 (comment)
- Loading branch information
Cole Chamberlain
committed
Nov 6, 2020
1 parent
8b9b595
commit b1b6376
Showing
5 changed files
with
823 additions
and
680 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// XHook - v1.4.9 - https://github.com/jpillora/xhook | ||
// Jaime Pillora <[email protected]> - MIT Copyright 2018 | ||
(function(undefined) { | ||
var AFTER, BEFORE, COMMON_EVENTS, EventEmitter, FETCH, FIRE, FormData, NativeFetch, NativeFormData, NativeXMLHttp, OFF, ON, READY_STATE, UPLOAD_EVENTS, WINDOW, XHookFetchRequest, XHookFormData, XHookHttpRequest, XMLHTTP, convertHeaders, depricatedProp, document, fakeEvent, mergeObjects, msie, nullify, proxyEvents, slice, useragent, xhook, _base, | ||
// Jaime Pillora <[email protected]> - MIT Copyright 2020 | ||
(function(window,undefined) { | ||
var AFTER, BEFORE, BODYLESS_STATUS_CODES, COMMON_EVENTS, EventEmitter, FETCH, FIRE, FormData, NativeFetch, NativeFormData, NativeXMLHttp, OFF, ON, READY_STATE, UPLOAD_EVENTS, WINDOW, XHookFetchRequest, XHookFormData, XHookHttpRequest, XMLHTTP, convertHeaders, depricatedProp, document, fakeEvent, mergeObjects, msie, nullify, proxyEvents, slice, useragent, xhook, _base, | ||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; | ||
|
||
WINDOW = null; | ||
|
@@ -38,6 +38,8 @@ UPLOAD_EVENTS = ['load', 'loadend', 'loadstart']; | |
|
||
COMMON_EVENTS = ['progress', 'abort', 'error', 'timeout']; | ||
|
||
BODYLESS_STATUS_CODES = [101, 204, 205, 304]; | ||
|
||
useragent = typeof navigator !== 'undefined' && navigator['useragent'] ? navigator.userAgent : ''; | ||
|
||
msie = parseInt((/msie (\d+)/.exec(useragent.toLowerCase()) || [])[1]); | ||
|
@@ -640,9 +642,10 @@ if (typeof WINDOW[FETCH] === "function") { | |
} | ||
}; | ||
done = function(userResponse) { | ||
var response; | ||
var body, response; | ||
if (userResponse !== void 0) { | ||
response = new Response(userResponse.body || userResponse.text, userResponse); | ||
body = BODYLESS_STATUS_CODES.includes(userResponse.status) ? null : userResponse.body || userResponse.text; | ||
response = new Response(body, userResponse); | ||
resolve(response); | ||
processAfter(response); | ||
return; | ||
|
@@ -697,4 +700,4 @@ if (typeof define === "function" && define.amd) { | |
WINDOW.xhook = xhook; | ||
} | ||
|
||
}.call(this)); | ||
}.call(this,window)); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.