diff --git a/History.md b/History.md index 2cd5e35309..b2b6c29757 100644 --- a/History.md +++ b/History.md @@ -1,5 +1,14 @@ ## v.NEXT + +### Utilities + +* New `beforeSend` option to `HTTP.call` on the client allows you to directly + access the `XMLHttpRequest` object and abort the call. #4419 #3243 #3266 + + +## in progress: v.1.1.1 + ### Blaze * Preparatory work for the yet-unreleased `react-template-helper` diff --git a/packages/http/httpcall_client.js b/packages/http/httpcall_client.js index 1ad8346e36..ceeb5532ac 100644 --- a/packages/http/httpcall_client.js +++ b/packages/http/httpcall_client.js @@ -13,7 +13,7 @@ * @param {Number} options.timeout Maximum time in milliseconds to wait for the request before failing. There is no timeout by default. * @param {Boolean} options.followRedirects If `true`, transparently follow HTTP redirects. Cannot be set to `false` on the client. Default `true`. * @param {Object} options.npmRequestOptions On the server, `HTTP.call` is implemented by using the [npm `request` module](https://www.npmjs.com/package/request). Any options in this object will be passed directly to the `request` invocation. - * @param {Function} options.beforeSend On the Client, this will be called before the request is sent to allow for more granular ajax manipulation, `xhr` object is passed as the first argument, returning false within this callback will cancel the request. + * @param {Function} options.beforeSend On the client, this will be called before the request is sent to allow for more direct manipulation of the underlying XMLHttpRequest object, which will be passed as the first argument. If the callback returns `false`, the request will be not be send. * @param {Function} [asyncCallback] Optional callback. If passed, the method runs asynchronously, instead of synchronously, and calls asyncCallback. On the client, this callback is required. */ HTTP.call = function(method, url, options, callback) { diff --git a/packages/http/httpcall_tests.js b/packages/http/httpcall_tests.js index 770084c279..449e1abeec 100644 --- a/packages/http/httpcall_tests.js +++ b/packages/http/httpcall_tests.js @@ -454,20 +454,18 @@ testAsyncMulti("httpcall - npmRequestOptions", [ } ]); -testAsyncMulti("httpcall - beforeSend", [ +Meteor.isClient && testAsyncMulti("httpcall - beforeSend", [ function (test, expect) { var fired = false; var bSend = function(xhr){ test.isFalse(fired); fired = true; - test.isTrue(temp1 instanceof XMLHttpRequest); + test.isTrue(xhr instanceof XMLHttpRequest); }; - if (Meteor.isClient) { - HTTP.get(url_prefix() + "/", {beforeSend: bSend}, function () { - test.isTrue(fired) - }); - } + HTTP.get(url_prefix() + "/", {beforeSend: bSend}, expect(function () { + test.isTrue(fired); + })); } ]);