Skip to content

Commit

Permalink
Implements null body for specific status codes per HTTP spec.
Browse files Browse the repository at this point in the history
- 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
Show file tree
Hide file tree
Showing 5 changed files with 823 additions and 680 deletions.
File renamed without changes.
15 changes: 9 additions & 6 deletions dist/xhook.js
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;
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -697,4 +700,4 @@ if (typeof define === "function" && define.amd) {
WINDOW.xhook = xhook;
}

}.call(this));
}.call(this,window));
4 changes: 2 additions & 2 deletions dist/xhook.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b1b6376

Please sign in to comment.