Skip to content

Commit

Permalink
refactor(http): remove unused put and delete methods (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
pablopalacios authored Aug 1, 2021
1 parent 7bfd20c commit ccd3efb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 176 deletions.
59 changes: 2 additions & 57 deletions libs/util/http.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ var DEFAULT_CONFIG = {
CONTENT_TYPE = 'Content-Type',
TYPE_JSON = 'application/json',
METHOD_GET = 'GET',
METHOD_PUT = 'PUT',
METHOD_POST = 'POST',
METHOD_DELETE = 'DELETE',
NULL = null;

var INITIAL_ATTEMPT = 0;
Expand All @@ -39,7 +37,7 @@ function normalizeHeaders(headers, method, isCors) {
if (!isCors) {
normalized['X-Requested-With'] = 'XMLHttpRequest';
}
var needContentType = method === METHOD_PUT || method === METHOD_POST;
var needContentType = method === METHOD_POST;
forEach(headers, function (v, field) {
if (field.toLowerCase() === 'content-type') {
if (needContentType) {
Expand Down Expand Up @@ -72,11 +70,7 @@ function shouldRetry(method, config, statusCode, attempt) {
return false;
}

var isIdempotent =
method === METHOD_GET ||
method === METHOD_PUT ||
method === METHOD_DELETE;
if (!isIdempotent && !config.unsafeAllowRetry) {
if (method === METHOD_POST && !config.unsafeAllowRetry) {
return false;
}

Expand Down Expand Up @@ -268,31 +262,6 @@ module.exports = {
);
},

/**
* @method put
* @param {String} url
* @param {Object} headers
* @param {Mixed} data
* @param {Object} config The config object. No retries for PUT.
* @param {Number} [config.timeout=3000] Timeout (in ms) for each request
* @param {Number} [config.retry.interval=200] The start interval unit (in ms).
* @param {Number} [config.retry.maxRetries=0] Number of max retries.
* @param {Number} [config.retry.statusCodes=[0, 408, 999]] Response status codes to be retried.
* @param {Boolean} [config.cors] Whether to enable CORS & use XDR on IE8/9.
* @param {Function} callback The callback function, with two params (error, response)
*/
put: function (url, headers, data, config, callback) {
return doXhr(
METHOD_PUT,
url,
headers,
data,
config,
INITIAL_ATTEMPT,
callback
);
},

/**
* @method post
* @param {String} url
Expand All @@ -318,28 +287,4 @@ module.exports = {
callback
);
},

/**
* @method delete
* @param {String} url
* @param {Object} headers
* @param {Object} config The config object. No retries for DELETE.
* @param {Number} [config.timeout=3000] Timeout (in ms) for each request
* @param {Number} [config.retry.interval=200] The start interval unit (in ms).
* @param {Number} [config.retry.maxRetries=0] Number of max retries.
* @param {Number} [config.retry.statusCodes=[0, 408, 999]] Response status codes to be retried.
* @param {Boolean} [config.cors] Whether to enable CORS & use XDR on IE8/9.
* @param {Function} callback The callback function, with two params (error, response)
*/
delete: function (url, headers, config, callback) {
return doXhr(
METHOD_DELETE,
url,
headers,
NULL,
config,
INITIAL_ATTEMPT,
callback
);
},
};
119 changes: 0 additions & 119 deletions tests/unit/libs/util/http.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,6 @@ describe('Client HTTP', function () {
});
});

it('PUT', function (done) {
http.put(
'/url',
{ 'X-Foo': 'foo' },
{ data: 'data' },
{},
function () {
expect(xhrOptions.length).to.equal(1);
var options = xhrOptions[0];
expect(options.url).to.equal('/url');
expect(options.headers['X-Requested-With']).to.equal(
'XMLHttpRequest'
);
expect(options.headers['X-Foo']).to.equal('foo');
expect(options.method).to.equal('PUT');
expect(options.body).to.eql('{"data":"data"}');
done();
}
);
});

it('POST', function (done) {
http.post(
'/url',
Expand All @@ -104,20 +83,6 @@ describe('Client HTTP', function () {
}
);
});

it('DELETE', function (done) {
http['delete']('/url', { 'X-Foo': 'foo' }, {}, function () {
expect(xhrOptions.length).to.equal(1);
var options = xhrOptions[0];
expect(options.url).to.equal('/url');
expect(options.headers['X-Requested-With']).to.equal(
'XMLHttpRequest'
);
expect(options.headers['X-Foo']).to.equal('foo');
expect(options.method).to.equal('DELETE');
done();
});
});
});

describe('#Successful CORS requests', function () {
Expand Down Expand Up @@ -152,27 +117,6 @@ describe('Client HTTP', function () {
);
});

it('PUT', function (done) {
http.put(
'/url',
{ 'X-Foo': 'foo' },
{ data: 'data' },
{ cors: true },
function () {
expect(xhrOptions.length).to.equal(1);
var options = xhrOptions[0];
expect(options.url).to.equal('/url');
expect(options.headers).to.not.have.property(
'X-Requested-With'
);
expect(options.headers['X-Foo']).to.equal('foo');
expect(options.method).to.equal('PUT');
expect(options.body).to.eql('{"data":"data"}');
done();
}
);
});

it('POST', function (done) {
http.post(
'/url',
Expand All @@ -193,25 +137,6 @@ describe('Client HTTP', function () {
}
);
});

it('DELETE', function (done) {
http['delete'](
'/url',
{ 'X-Foo': 'foo' },
{ cors: true },
function () {
expect(xhrOptions.length).to.equal(1);
var options = xhrOptions[0];
expect(options.url).to.equal('/url');
expect(options.headers).to.not.have.property(
'X-Requested-With'
);
expect(options.headers['X-Foo']).to.equal('foo');
expect(options.method).to.equal('DELETE');
done();
}
);
});
});

describe('#400 requests', function () {
Expand Down Expand Up @@ -385,20 +310,6 @@ describe('Client HTTP', function () {
});
});

it('should use xhrTimeout for PUT', function (done) {
http.put(
'/url',
{ 'X-Foo': 'foo' },
{ data: 'data' },
config,
function () {
var options = xhrOptions[0];
expect(options.timeout).to.equal(3000);
done();
}
);
});

it('should use xhrTimeout for POST', function (done) {
http.post(
'/url',
Expand All @@ -412,14 +323,6 @@ describe('Client HTTP', function () {
}
);
});

it('should use xhrTimeout for DELETE', function (done) {
http['delete']('/url', { 'X-Foo': 'foo' }, config, function () {
var options = xhrOptions[0];
expect(options.timeout).to.equal(3000);
done();
});
});
});

describe('#Timeout set for individual call', function () {
Expand All @@ -435,20 +338,6 @@ describe('Client HTTP', function () {
});
});

it('should override default xhrTimeout for PUT', function (done) {
http.put(
'/url',
{ 'X-Foo': 'foo' },
{ data: 'data' },
config,
function () {
var options = xhrOptions[0];
expect(options.timeout).to.equal(6000);
done();
}
);
});

it('should override default xhrTimeout for POST', function (done) {
http.post(
'/url',
Expand All @@ -462,14 +351,6 @@ describe('Client HTTP', function () {
}
);
});

it('should override default xhrTimeout for DELETE', function (done) {
http['delete']('/url', { 'X-Foo': 'foo' }, config, function () {
var options = xhrOptions[0];
expect(options.timeout).to.equal(6000);
done();
});
});
});
});

Expand Down

0 comments on commit ccd3efb

Please sign in to comment.