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

@cloudflare/util-http

Package Overview
Dependencies
Maintainers
26
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.4 to 1.0.6

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

<a name="1.0.6"></a>
## [1.0.6](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/util-http@1.0.4...@cloudflare/util-http@1.0.6) (2018-06-07)
**Note:** Version bump only for package @cloudflare/util-http
<a name="1.0.4"></a>

@@ -8,0 +16,0 @@ ## [1.0.4](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/util-http@1.0.2...@cloudflare/util-http@1.0.4) (2018-06-07)

46

es/http.js

@@ -1,5 +0,1 @@

Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

@@ -9,25 +5,11 @@

exports.beforeSend = beforeSend;
exports.clearBeforeSend = clearBeforeSend;
exports.request = request;
exports.get = get;
exports.post = post;
exports.put = put;
exports.patch = patch;
exports.del = del;
import './polyfillFetchInEdge';
import 'isomorphic-fetch';
require('./polyfillFetchInEdge');
import createLogger from '@cloudflare/util-logger';
require('isomorphic-fetch');
var logRequest = createLogger('http:request');
var logError = createLogger('http:error');
var logSuccess = createLogger('http:success');
var _utilLogger = require('@cloudflare/util-logger');
var _utilLogger2 = _interopRequireDefault(_utilLogger);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var logRequest = (0, _utilLogger2.default)('http:request');
var logError = (0, _utilLogger2.default)('http:error');
var logSuccess = (0, _utilLogger2.default)('http:success');
// Store beforeSend callbacks.

@@ -48,7 +30,7 @@ var beforeSendCallbacks = [];

*/
function beforeSend(callback) {
export function beforeSend(callback) {
beforeSendCallbacks.push(callback);
}
function clearBeforeSend() {
export function clearBeforeSend() {
beforeSendCallbacks = [];

@@ -201,3 +183,3 @@ }

*/
function request(method, url, opts, callback) {
export function request(method, url, opts, callback) {
if (typeof opts === 'function') {

@@ -284,3 +266,3 @@ callback = opts;

*/
function get() {
export function get() {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {

@@ -296,3 +278,3 @@ args[_key] = arguments[_key];

*/
function post() {
export function post() {
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {

@@ -308,3 +290,3 @@ args[_key2] = arguments[_key2];

*/
function put() {
export function put() {
for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {

@@ -320,3 +302,3 @@ args[_key3] = arguments[_key3];

*/
function patch() {
export function patch() {
for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {

@@ -332,3 +314,3 @@ args[_key4] = arguments[_key4];

*/
function del() {
export function del() {
for (var _len5 = arguments.length, args = Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {

@@ -335,0 +317,0 @@ args[_key5] = arguments[_key5];

@@ -1,15 +0,1 @@

Object.defineProperty(exports, "__esModule", {
value: true
});
var _http = require('./http');
Object.keys(_http).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _http[key];
}
});
});
export * from './http';

@@ -6,7 +6,2 @@ 'use strict';

});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _slicedToArray = function () { function sliceIterator(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"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
exports.beforeSend = beforeSend;

@@ -31,8 +26,8 @@ exports.clearBeforeSend = clearBeforeSend;

var logRequest = (0, _utilLogger2.default)('http:request');
var logError = (0, _utilLogger2.default)('http:error');
var logSuccess = (0, _utilLogger2.default)('http:success');
const logRequest = (0, _utilLogger2.default)('http:request');
const logError = (0, _utilLogger2.default)('http:error');
const logSuccess = (0, _utilLogger2.default)('http:success');
// Store beforeSend callbacks.
var beforeSendCallbacks = [];
let beforeSendCallbacks = [];

@@ -65,33 +60,10 @@ /**

function toQueryParams(kvs) {
var queryParams = [];
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) {
_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)) {

@@ -102,16 +74,10 @@ queryParams.push([k, kvs[k]]);

}
return queryParams.map(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2),
k = _ref2[0],
v = _ref2[1];
return encodeURIComponent(k) + '=' + 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;

@@ -122,29 +88,6 @@ 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;
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) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
const headersMap = new Map(headers);
for (let [k, v] of headersMap) {
hash[k] = v;
hash[k.toLowerCase()] = v;
}

@@ -160,6 +103,6 @@ }

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

@@ -216,5 +159,3 @@ /**

// Allow beforeSend to modify request options.
beforeSendCallbacks.forEach(function (cb) {
return cb(opts);
});
beforeSendCallbacks.forEach(cb => cb(opts));

@@ -234,3 +175,3 @@ method = opts.method;

// null or undefined.
for (var h in opts.headers) {
for (const h in opts.headers) {
if (opts.headers[h] === null || typeof opts.headers[h] === 'undefined') {

@@ -244,5 +185,3 @@ delete opts.headers[h];

// Content-Type
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);

@@ -255,16 +194,16 @@ if (!opts.headers.has('Content-Type')) {

if (opts.parameters) {
url += '' + (url.indexOf('?') === -1 ? '?' : '&') + toQueryParams(opts.parameters);
url += `${url.indexOf('?') === -1 ? '?' : '&'}${toQueryParams(opts.parameters)}`;
}
var logMessage = method + ' ' + 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 = logMessage + ' (' + status + ' ' + response.statusText + ')';
.then(response => {
const headers = toHash(response.headers);
const status = response.status;
logMessage = `${logMessage} (${status} ${response.statusText})`;
return response.text().then(function (text) {
var wrappedResponse = wrapResponse(headers, status, text, response);
return response.text().then(text => {
const wrappedResponse = wrapResponse(headers, status, text, response);
if (response.ok) {

@@ -277,3 +216,3 @@ logSuccess(logMessage);

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

@@ -288,8 +227,4 @@ callback && callback(err);

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

@@ -300,8 +235,4 @@

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

@@ -312,8 +243,4 @@

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

@@ -324,8 +251,4 @@

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

@@ -336,8 +259,4 @@

*/
function del() {
for (var _len5 = arguments.length, args = Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
args[_key5] = arguments[_key5];
}
return request.apply(undefined, ['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.4",
"version": "1.0.6",
"main": "lib/index.js",

@@ -15,3 +15,3 @@ "module": "es/index.js",

"dependencies": {
"@cloudflare/util-logger": "^1.0.4",
"@cloudflare/util-logger": "^1.0.6",
"isomorphic-fetch": "^2.2.1"

@@ -18,0 +18,0 @@ },

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