Skip to content

Commit

Permalink
feat(xhrbackend): use backend for xhr creation
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Sep 16, 2018
1 parent d750e0a commit 4ab6a8a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/adapters/xhr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { createError } from '../utils/createError';
import { getObserverHandler } from '../utils/getObserverHandler';
import { parseHeaders } from '../utils/parseHeaders';
import { buildURL, isURLSameOrigin } from '../utils/urls';
import { xhrBackend } from './xhrBackend';

const XSSI_PREFIX = /^\)\]\}',?\n/;

Expand All @@ -37,7 +38,7 @@ const xhrAdapter = <T = any>(config: RequestConfigBrowser) =>
const { reportProgress, withCredentials } = config;
const { emitError, emitComplete } = getObserverHandler(observer);
// Start by setting up the XHR object with request method, URL, and withCredentials flag.
const xhr = new XMLHttpRequest();
const xhr = xhrBackend();

// This is the return from the Observable function, which is the
// request cancellation handler.
Expand Down Expand Up @@ -102,7 +103,7 @@ const xhrAdapter = <T = any>(config: RequestConfigBrowser) =>
}

// Add headers to the request
if ('setRequestHeader' in xhr) {
if ('setRequestHeader' in xhr && !!requestHeaders) {
((Object as any).entries(requestHeaders) as Array<[string, string]>)
.filter(
([key]) =>
Expand Down
6 changes: 6 additions & 0 deletions src/adapters/xhrBackend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Naive factory to global XHR.
*/
const xhrBackend = () => new XMLHttpRequest();

export { xhrBackend };

0 comments on commit 4ab6a8a

Please sign in to comment.