Skip to content

Commit 9500e6e

Browse files
author
Marcos Andrei Ivanechtchuk
committed
testing fix
1 parent d3ccdb0 commit 9500e6e

File tree

5 files changed

+57
-20
lines changed

5 files changed

+57
-20
lines changed

dist/cep-promise-browser.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
(function (global, factory) {
2-
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3-
typeof define === 'function' && define.amd ? define(factory) :
4-
(global.cep = factory());
5-
}(this, (function () { 'use strict';
2+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('os')) :
3+
typeof define === 'function' && define.amd ? define(['os'], factory) :
4+
(global.cep = factory(global.os));
5+
}(this, (function (os) { 'use strict';
66

77
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
88
return typeof obj;
@@ -78,7 +78,7 @@ var index = typeof fetch == 'function' ? fetch.bind() : function (url, options)
7878
return new Promise(function (resolve, reject) {
7979
var request = new XMLHttpRequest();
8080

81-
request.open(options.method || 'get', url);
81+
request.open(options.method || 'get', url, true);
8282

8383
for (var i in options.headers) {
8484
request.setRequestHeader(i, options.headers[i]);
@@ -92,23 +92,23 @@ var index = typeof fetch == 'function' ? fetch.bind() : function (url, options)
9292

9393
request.onerror = reject;
9494

95-
request.send(options.body);
95+
request.send(options.body || null);
9696

9797
function response() {
9898
var _keys = [],
9999
all = [],
100100
headers = {},
101101
header;
102102

103-
request.getAllResponseHeaders().replace(/^(.*?):\s*([\s\S]*?)$/gm, function (m, key, value) {
103+
request.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm, function (m, key, value) {
104104
_keys.push(key = key.toLowerCase());
105105
all.push([key, value]);
106106
header = headers[key];
107107
headers[key] = header ? header + "," + value : value;
108108
});
109109

110110
return {
111-
ok: (request.status / 200 | 0) == 1, // 200-299
111+
ok: (request.status / 100 | 0) == 2, // 200-299
112112
status: request.status,
113113
statusText: request.statusText,
114114
url: request.responseURL,
@@ -358,15 +358,27 @@ function throwApplicationError$2(error) {
358358
throw serviceError;
359359
}
360360

361+
function isBrowser() {
362+
return (typeof window === 'undefined' ? 'undefined' : _typeof(window)) !== undefined;
363+
}
364+
365+
function isHttps() {
366+
return location && location.protocol === 'https:';
367+
}
368+
369+
function shouldUseProxy() {
370+
return isBrowser && !isHttps();
371+
}
372+
361373
/* istanbul ignore next */
362374
function injectProxy(Service) {
363375
return function (cepWithLeftPad) {
364376
return Service(cepWithLeftPad, PROXY_URL);
365377
};
366378
}
367379

368-
var CepAbertoService = typeof process === 'undefined' ? injectProxy(fetchCepAbertoService) : fetchCepAbertoService;
369-
var CorreiosService = typeof process === 'undefined' ? injectProxy(fetchCorreiosService) : fetchCorreiosService;
380+
var CepAbertoService = shouldUseProxy() ? injectProxy(fetchCepAbertoService) : fetchCepAbertoService;
381+
var CorreiosService = shouldUseProxy() ? injectProxy(fetchCorreiosService) : fetchCorreiosService;
370382
var ViaCepService = fetchViaCepService;
371383

372384
var reverse = function reverse(promise) {

dist/cep-promise-browser.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cep-promise.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
(function (global, factory) {
2-
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('isomorphic-unfetch')) :
3-
typeof define === 'function' && define.amd ? define(['isomorphic-unfetch'], factory) :
4-
(global.cep = factory(global.fetch));
5-
}(this, (function (fetch) { 'use strict';
2+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('isomorphic-unfetch'), require('os')) :
3+
typeof define === 'function' && define.amd ? define(['isomorphic-unfetch', 'os'], factory) :
4+
(global.cep = factory(global.fetch,global.os));
5+
}(this, (function (fetch,os) { 'use strict';
66

77
fetch = fetch && fetch.hasOwnProperty('default') ? fetch['default'] : fetch;
88

@@ -283,15 +283,27 @@ function throwApplicationError$2(error) {
283283
throw serviceError;
284284
}
285285

286+
function isBrowser() {
287+
return (typeof window === 'undefined' ? 'undefined' : _typeof(window)) !== undefined;
288+
}
289+
290+
function isHttps() {
291+
return location && location.protocol === 'https:';
292+
}
293+
294+
function shouldUseProxy() {
295+
return isBrowser && !isHttps();
296+
}
297+
286298
/* istanbul ignore next */
287299
function injectProxy(Service) {
288300
return function (cepWithLeftPad) {
289301
return Service(cepWithLeftPad, PROXY_URL);
290302
};
291303
}
292304

293-
var CepAbertoService = typeof process === 'undefined' ? injectProxy(fetchCepAbertoService) : fetchCepAbertoService;
294-
var CorreiosService = typeof process === 'undefined' ? injectProxy(fetchCorreiosService) : fetchCorreiosService;
305+
var CepAbertoService = shouldUseProxy() ? injectProxy(fetchCepAbertoService) : fetchCepAbertoService;
306+
var CorreiosService = shouldUseProxy() ? injectProxy(fetchCorreiosService) : fetchCorreiosService;
295307
var ViaCepService = fetchViaCepService;
296308

297309
var reverse = function reverse(promise) {

0 commit comments

Comments
 (0)