Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cloudflare/util-http

Package Overview
Dependencies
Maintainers
27
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cloudflare/util-http - npm Package Compare versions

Comparing version 1.0.10 to 1.0.11

src/http.ts

15

CHANGELOG.md

@@ -6,3 +6,14 @@ # Change Log

<a name="1.0.10"></a>
<a name="1.0.11"></a>
## [1.0.11](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/util-http@1.0.10...@cloudflare/util-http@1.0.11) (2018-08-24)
### Bug Fixes
* **util-http:** UI-1025 missing Headers support fixed in Edge 16.16216 ([f917e15](http://stash.cfops.it:7999/fe/stratus/commits/f917e15))
<a name="1.0.10"></a>
## [1.0.10](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/util-http@1.0.9...@cloudflare/util-http@1.0.10) (2018-07-25)

@@ -15,3 +26,3 @@

<a name="1.0.9"></a>
<a name="1.0.9"></a>
## [1.0.9](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/util-http@1.0.8...@cloudflare/util-http@1.0.9) (2018-07-16)

@@ -18,0 +29,0 @@

178

es/http.js

@@ -1,19 +0,8 @@

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import './polyfillFetchInEdge';
import 'isomorphic-fetch';
import createLogger from '@cloudflare/util-logger';
var logRequest = createLogger('http:request');
var logError = createLogger('http:error');
var logSuccess = createLogger('http:success'); // Store beforeSend callbacks.
var beforeSendCallbacks = [];
const logRequest = createLogger('http:request');
const logError = createLogger('http:error');
const logSuccess = createLogger('http:success');
// Store beforeSend callbacks.
let beforeSendCallbacks = [];
/**

@@ -44,33 +33,10 @@ * Modify request options before they are sent.

function toQueryParams(kvs) {
var queryParams = []; // Clones the input
const queryParams = []; // Clones the input
if (Array.isArray(kvs) || kvs instanceof Map) {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = kvs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _step$value = _slicedToArray(_step.value, 2),
k = _step$value[0],
v = _step$value[1];
queryParams.push([k, v]);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
for (let [k, v] of kvs) {
queryParams.push([k, v]);
}
} else {
for (var k in kvs) {
for (let k in kvs) {
if (kvs.hasOwnProperty(k)) {

@@ -82,17 +48,11 @@ queryParams.push([k, kvs[k]]);

return queryParams.map(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2),
k = _ref2[0],
v = _ref2[1];
return "".concat(encodeURIComponent(k), "=").concat(encodeURIComponent(v));
}).join('&');
return queryParams.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`).join('&');
}
function toHash(headers) {
var hash = Object.create(null);
const hash = Object.create(null);
if (headers._headers) {
Object.keys(headers._headers).forEach(function (key) {
var value = Array.isArray(headers._headers[key]) ? headers._headers[key][0] : headers._headers[key];
Object.keys(headers._headers).forEach(key => {
const value = Array.isArray(headers._headers[key]) ? headers._headers[key][0] : headers._headers[key];
hash[key] = value;

@@ -103,29 +63,7 @@ hash[key.toLowerCase()] = value;

// converting to Map allows for .. of in Edge
var headersMap = new Map(headers);
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
const headersMap = new Map(headers);
try {
for (var _iterator2 = headersMap[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _step2$value = _slicedToArray(_step2.value, 2),
k = _step2$value[0],
v = _step2$value[1];
hash[k] = v;
hash[k.toLowerCase()] = v;
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
for (let [k, v] of headersMap) {
hash[k] = v;
hash[k.toLowerCase()] = v;
}

@@ -145,11 +83,11 @@ }

return {
headers: headers,
status: status,
body: body,
text: text,
response: response
headers,
status,
body,
text,
response
};
}
var BODYLESS_METHODS = ['GET', 'HEAD'];
const BODYLESS_METHODS = ['GET', 'HEAD'];
/**

@@ -204,5 +142,3 @@ * Perform an http request. This method uses WHATWG's fetch API and returns a

beforeSendCallbacks.forEach(function (cb) {
return cb(opts);
});
beforeSendCallbacks.forEach(cb => cb(opts));
method = opts.method;

@@ -218,4 +154,6 @@ url = opts.url;

for (var h in opts.headers) {
for (const h in opts.headers) {
// @ts-ignore: this is technically supported by the headers TS Api
if (opts.headers[h] === null || typeof opts.headers[h] === 'undefined') {
// @ts-ignore: this is technically supported by the headers TS Api
delete opts.headers[h];

@@ -228,5 +166,3 @@ }

if (!opts.skipBodyTransform && BODYLESS_METHODS.every(function (m) {
return method.toUpperCase() !== m;
}) && opts.body && _typeof(opts.body) === 'object') {
if (!opts.skipBodyTransform && BODYLESS_METHODS.every(m => method.toUpperCase() !== m) && opts.body && typeof opts.body === 'object') {
opts.body = JSON.stringify(opts.body);

@@ -240,14 +176,14 @@

if (opts.parameters) {
url += "".concat(url.indexOf('?') === -1 ? '?' : '&').concat(toQueryParams(opts.parameters));
url += `${url.indexOf('?') === -1 ? '?' : '&'}${toQueryParams(opts.parameters)}`;
}
var logMessage = "".concat(method, " ").concat(url);
let logMessage = `${method} ${url}`;
logRequest(logMessage);
return fetch(url, opts) // eslint-disable-line compat/compat
.then(function (response) {
var headers = toHash(response.headers);
var status = response.status;
logMessage = "".concat(logMessage, " (").concat(status, " ").concat(response.statusText, ")");
return response.text().then(function (text) {
var wrappedResponse = wrapResponse(headers, status, text, response);
.then(response => {
const headers = toHash(response.headers);
const status = response.status;
logMessage = `${logMessage} (${status} ${response.statusText})`;
return response.text().then(text => {
const wrappedResponse = wrapResponse(headers, status, text, response);

@@ -262,3 +198,3 @@ if (response.ok) {

});
}).catch(function (err) {
}).catch(err => {
logError(logMessage);

@@ -273,8 +209,4 @@ callback && callback(err);

export function get() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return request.apply(void 0, ['GET'].concat(args));
export function get(...args) {
return request('GET', ...args);
}

@@ -285,8 +217,4 @@ /**

export function post() {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return request.apply(void 0, ['POST'].concat(args));
export function post(...args) {
return request('POST', ...args);
}

@@ -297,8 +225,4 @@ /**

export function put() {
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
args[_key3] = arguments[_key3];
}
return request.apply(void 0, ['PUT'].concat(args));
export function put(...args) {
return request('PUT', ...args);
}

@@ -309,8 +233,4 @@ /**

export function patch() {
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
args[_key4] = arguments[_key4];
}
return request.apply(void 0, ['PATCH'].concat(args));
export function patch(...args) {
return request('PATCH', ...args);
}

@@ -321,8 +241,4 @@ /**

export function del() {
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
args[_key5] = arguments[_key5];
}
return request.apply(void 0, ['DELETE'].concat(args));
export function del(...args) {
return request('DELETE', ...args);
}

@@ -15,4 +15,2 @@ "use strict";

require("./polyfillFetchInEdge");
require("isomorphic-fetch");

@@ -24,17 +22,7 @@

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
var logRequest = (0, _utilLogger.default)('http:request');
var logError = (0, _utilLogger.default)('http:error');
var logSuccess = (0, _utilLogger.default)('http:success'); // Store beforeSend callbacks.
var beforeSendCallbacks = [];
const logRequest = (0, _utilLogger.default)('http:request');
const logError = (0, _utilLogger.default)('http:error');
const logSuccess = (0, _utilLogger.default)('http:success');
// Store beforeSend callbacks.
let beforeSendCallbacks = [];
/**

@@ -66,33 +54,10 @@ * Modify request options before they are sent.

function toQueryParams(kvs) {
var queryParams = []; // Clones the input
const queryParams = []; // Clones the input
if (Array.isArray(kvs) || kvs instanceof Map) {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = kvs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _step$value = _slicedToArray(_step.value, 2),
k = _step$value[0],
v = _step$value[1];
queryParams.push([k, v]);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
for (let [k, v] of kvs) {
queryParams.push([k, v]);
}
} else {
for (var k in kvs) {
for (let k in kvs) {
if (kvs.hasOwnProperty(k)) {

@@ -104,17 +69,11 @@ queryParams.push([k, kvs[k]]);

return queryParams.map(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2),
k = _ref2[0],
v = _ref2[1];
return "".concat(encodeURIComponent(k), "=").concat(encodeURIComponent(v));
}).join('&');
return queryParams.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`).join('&');
}
function toHash(headers) {
var hash = Object.create(null);
const hash = Object.create(null);
if (headers._headers) {
Object.keys(headers._headers).forEach(function (key) {
var value = Array.isArray(headers._headers[key]) ? headers._headers[key][0] : headers._headers[key];
Object.keys(headers._headers).forEach(key => {
const value = Array.isArray(headers._headers[key]) ? headers._headers[key][0] : headers._headers[key];
hash[key] = value;

@@ -125,29 +84,7 @@ hash[key.toLowerCase()] = value;

// converting to Map allows for .. of in Edge
var headersMap = new Map(headers);
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
const headersMap = new Map(headers);
try {
for (var _iterator2 = headersMap[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _step2$value = _slicedToArray(_step2.value, 2),
k = _step2$value[0],
v = _step2$value[1];
hash[k] = v;
hash[k.toLowerCase()] = v;
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
for (let [k, v] of headersMap) {
hash[k] = v;
hash[k.toLowerCase()] = v;
}

@@ -167,11 +104,11 @@ }

return {
headers: headers,
status: status,
body: body,
text: text,
response: response
headers,
status,
body,
text,
response
};
}
var BODYLESS_METHODS = ['GET', 'HEAD'];
const BODYLESS_METHODS = ['GET', 'HEAD'];
/**

@@ -226,5 +163,3 @@ * Perform an http request. This method uses WHATWG's fetch API and returns a

beforeSendCallbacks.forEach(function (cb) {
return cb(opts);
});
beforeSendCallbacks.forEach(cb => cb(opts));
method = opts.method;

@@ -240,4 +175,6 @@ url = opts.url;

for (var h in opts.headers) {
for (const h in opts.headers) {
// @ts-ignore: this is technically supported by the headers TS Api
if (opts.headers[h] === null || typeof opts.headers[h] === 'undefined') {
// @ts-ignore: this is technically supported by the headers TS Api
delete opts.headers[h];

@@ -250,5 +187,3 @@ }

if (!opts.skipBodyTransform && BODYLESS_METHODS.every(function (m) {
return method.toUpperCase() !== m;
}) && opts.body && _typeof(opts.body) === 'object') {
if (!opts.skipBodyTransform && BODYLESS_METHODS.every(m => method.toUpperCase() !== m) && opts.body && typeof opts.body === 'object') {
opts.body = JSON.stringify(opts.body);

@@ -262,14 +197,14 @@

if (opts.parameters) {
url += "".concat(url.indexOf('?') === -1 ? '?' : '&').concat(toQueryParams(opts.parameters));
url += `${url.indexOf('?') === -1 ? '?' : '&'}${toQueryParams(opts.parameters)}`;
}
var logMessage = "".concat(method, " ").concat(url);
let logMessage = `${method} ${url}`;
logRequest(logMessage);
return fetch(url, opts) // eslint-disable-line compat/compat
.then(function (response) {
var headers = toHash(response.headers);
var status = response.status;
logMessage = "".concat(logMessage, " (").concat(status, " ").concat(response.statusText, ")");
return response.text().then(function (text) {
var wrappedResponse = wrapResponse(headers, status, text, response);
.then(response => {
const headers = toHash(response.headers);
const status = response.status;
logMessage = `${logMessage} (${status} ${response.statusText})`;
return response.text().then(text => {
const wrappedResponse = wrapResponse(headers, status, text, response);

@@ -284,3 +219,3 @@ if (response.ok) {

});
}).catch(function (err) {
}).catch(err => {
logError(logMessage);

@@ -296,8 +231,4 @@ callback && callback(err);

function get() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return request.apply(void 0, ['GET'].concat(args));
function get(...args) {
return request('GET', ...args);
}

@@ -309,8 +240,4 @@ /**

function post() {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return request.apply(void 0, ['POST'].concat(args));
function post(...args) {
return request('POST', ...args);
}

@@ -322,8 +249,4 @@ /**

function put() {
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
args[_key3] = arguments[_key3];
}
return request.apply(void 0, ['PUT'].concat(args));
function put(...args) {
return request('PUT', ...args);
}

@@ -335,8 +258,4 @@ /**

function patch() {
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
args[_key4] = arguments[_key4];
}
return request.apply(void 0, ['PATCH'].concat(args));
function patch(...args) {
return request('PATCH', ...args);
}

@@ -348,8 +267,4 @@ /**

function del() {
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
args[_key5] = arguments[_key5];
}
return request.apply(void 0, ['DELETE'].concat(args));
function del(...args) {
return request('DELETE', ...args);
}

@@ -13,3 +13,3 @@ "use strict";

enumerable: true,
get: function get() {
get: function () {
return _http[key];

@@ -16,0 +16,0 @@ }

{
"name": "@cloudflare/util-http",
"description": "Cloudflare HTTP Util",
"version": "1.0.10",
"version": "1.0.11",
"main": "lib/index.js",

@@ -6,0 +6,0 @@ "module": "es/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc