Skip to content

Commit 6054347

Browse files
committed
Fixed merge issues
2 parents fc735f5 + a0e1338 commit 6054347

File tree

8 files changed

+96
-16
lines changed

8 files changed

+96
-16
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,19 @@ This is undoubtaly the most important option. As this module tries to be as tra
7676

7777
The default time in milliseconds the http batcher should wait to collection all request to this domain after the first http call that can be batched has been collect. This defaults to 100ms. Therefore if you send a HTTP GET call that can be batched the HTTP batcher will receive this call and wait a further 100ms before sending the call in order to wait for other calls to the same domain in order to add them to the current batch request. If no other calls are collected the initial HTTP call will be allowed to continue as normal and will not be batched unless the config property - **minimumBatchSize** is set to one.
7878

79+
<h4 id="flushing-all-requests">Immediately flushing all pending requests</h4>
80+
In some instances you might want to immediately send all pending request regardless of if the request quota or timeout limit has been reached. To do this you can simply call the flush method on the httpBatcher service and optionally pass in the url of the batch endpoint you want to flush (if no parameter is passed in all pending requests to all endpoints are flushed).
81+
82+
```language-javascript
83+
angular.module('myApp', ['jcs.angular-http-batch']);
84+
.run([
85+
'httpBatcher',
86+
function (httpBatcher) {
87+
httpBatcher.flush();
88+
}
89+
]);
90+
```
91+
7992
<h3 id="angular-http-batcher-getting-started-with-asp-web-api">Configuring .Net Web API 2 for Batch Requests</h3>
8093

8194
This is **really** simple the web api team have done a really good job here. To enable batch request handling you just add a new route to your application and the rest is done for you! It's so easy I don't see any reason for you not to do it! See [this link](http://blogs.msdn.com/b/webdev/archive/2013/11/01/introducing-batch-support-in-web-api-and-web-api-odata.aspx) for a more detailed setup guide. Just add the below code to your web api configuration class and you are good to go!

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-http-batcher",
3-
"version": "1.6.0",
3+
"version": "1.7.0",
44
"description": "Enables transparent HTTP batch requests with Angular",
55
"main": "dist/angular-http-batch.min.js",
66
"keywords": [

dist/ChangeLog.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
16/03/2015 V1.6.0
1+
16/03/2015 V1.7.0
22
Fixed issue with parsing the response string into a json object with having more than two dashes '--' in the returned data.
33

4+
12/01/2015 V1.6.0
5+
Added a flush method to the httpBatcher service which will immediately send all the pending batch requests regardless of batch quota or time limits being hit.
6+
47
19/11/2014 V1.5.0
58
When batching requests that have request bodies, such as "POST" requests, the standard angular request transforms convert objects into json strings.
69
When angular-http-batcher calls angular.toJson again, we end up with a single json string, instead of a json encoding of the object in the batched request.

dist/angular-http-batch.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* angular-http-batcher - v1.6.0 - 2015-03-16
2+
* angular-http-batcher - v1.7.0 - 2015-03-18
33
* https://github.com/jonsamwell/angular-http-batcher
44
* Copyright (c) 2015 Jon Samwell
55
*/
@@ -214,6 +214,15 @@ angular.module(window.ahb.name).factory('httpBatcher', [
214214
}
215215

216216
batchRequestManager.addRequest(request);
217+
},
218+
219+
flush = function (batchEndpointUrl) {
220+
angular.forEach(currentBatchedRequests, function (val, key) {
221+
var shouldFlush = batchEndpointUrl === undefined || batchEndpointUrl && key.toLocaleLowerCase() === batchEndpointUrl.toLocaleLowerCase();
222+
if (shouldFlush) {
223+
val.flush();
224+
}
225+
});
217226
};
218227

219228
BatchRequestPartParser.prototype = (function () {
@@ -379,14 +388,18 @@ angular.module(window.ahb.name).factory('httpBatcher', [
379388
this.requests.push(request);
380389

381390
if (this.requests.length > this.config.maxBatchedRequestPerCall) {
382-
$timeout.cancel(this.currentTimeoutToken);
383-
this.currentTimeoutToken = undefined;
384-
this.send();
391+
this.flush();
385392
}
386393

387394
return true;
388395
},
389396

397+
flush = function () {
398+
$timeout.cancel(this.currentTimeoutToken);
399+
this.currentTimeoutToken = undefined;
400+
this.send();
401+
},
402+
390403
getUrlInfo = function (url) {
391404
var protocol,
392405
host,
@@ -432,13 +445,15 @@ angular.module(window.ahb.name).factory('httpBatcher', [
432445

433446
return {
434447
addRequest: addRequest,
435-
send: send
448+
send: send,
449+
flush: flush
436450
};
437451
}());
438452

439453
return {
440454
canBatchRequest: canBatchRequest,
441-
batchRequest: batchRequest
455+
batchRequest: batchRequest,
456+
flush: flush
442457
};
443458
}
444459
]);

dist/angular-http-batch.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-http-batcher",
3-
"version": "1.6.0",
3+
"version": "1.7.0",
44
"description": "Enables transparent HTTP batch requests with Angular",
55
"main": "angular-http-batcher.min.js",
66
"scripts": {

src/services/httpBatcher.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ angular.module(window.ahb.name).factory('httpBatcher', [
6262
}
6363

6464
batchRequestManager.addRequest(request);
65+
},
66+
67+
flush = function (batchEndpointUrl) {
68+
angular.forEach(currentBatchedRequests, function (val, key) {
69+
var shouldFlush = batchEndpointUrl === undefined || batchEndpointUrl && key.toLocaleLowerCase() === batchEndpointUrl.toLocaleLowerCase();
70+
if (shouldFlush) {
71+
val.flush();
72+
}
73+
});
6574
};
6675

6776
BatchRequestPartParser.prototype = (function () {
@@ -227,14 +236,18 @@ angular.module(window.ahb.name).factory('httpBatcher', [
227236
this.requests.push(request);
228237

229238
if (this.requests.length > this.config.maxBatchedRequestPerCall) {
230-
$timeout.cancel(this.currentTimeoutToken);
231-
this.currentTimeoutToken = undefined;
232-
this.send();
239+
this.flush();
233240
}
234241

235242
return true;
236243
},
237244

245+
flush = function () {
246+
$timeout.cancel(this.currentTimeoutToken);
247+
this.currentTimeoutToken = undefined;
248+
this.send();
249+
},
250+
238251
getUrlInfo = function (url) {
239252
var protocol,
240253
host,
@@ -280,13 +293,15 @@ angular.module(window.ahb.name).factory('httpBatcher', [
280293

281294
return {
282295
addRequest: addRequest,
283-
send: send
296+
send: send,
297+
flush: flush
284298
};
285299
}());
286300

287301
return {
288302
canBatchRequest: canBatchRequest,
289-
batchRequest: batchRequest
303+
batchRequest: batchRequest,
304+
flush: flush
290305
};
291306
}
292307
]);

tests/services/httpBatcher.spec.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,40 @@
612612
});
613613
});
614614
});
615+
616+
describe('flush', function () {
617+
it('should send the batched request before the timeout to send the batch has been reached', function (done) {
618+
var batchConfig = {
619+
batchEndpointUrl: 'http://www.someservice.com/batch',
620+
batchRequestCollectionDelay: 10000,
621+
minimumBatchSize: 1
622+
},
623+
postData = '--some_boundary_mocked\r\nContent-Type: application/http; msgtype=request\r\n\r\nGET /resource HTTP/1.1\r\nHost: www.gogle.com\r\n\r\n\r\n--some_boundary_mocked--',
624+
responseData = '--some_boundary_mocked\r\nContent-Type: application/http; msgtype=response\r\n\r\n' +
625+
'HTTP/1.1 200 OK\r\nContent-Type: application/json; charset=utf-8\r\n\r\n' +
626+
'[{"Name":"Product 1","Id":1,"StockQuantity":100},{"Name":"Product 2","Id":2,"StockQuantity":2},{"Name":"Product 3","Id":3,"StockQuantity":32432}]' +
627+
'\r\n--some_boundary_mocked--\r\n';
628+
629+
$httpBackend.expectPOST(batchConfig.batchEndpointUrl, postData).respond(200, responseData, {
630+
'content-type': 'multipart/mixed; boundary="some_boundary_mocked"'
631+
}, 'OK');
632+
633+
sandbox.stub(httpBatchConfig, 'calculateBoundary').returns('some_boundary_mocked');
634+
sandbox.stub(httpBatchConfig, 'getBatchConfig').returns(batchConfig);
635+
636+
httpBatcher.batchRequest({
637+
url: 'http://www.gogle.com/resource',
638+
method: 'GET',
639+
callback: function () {
640+
done();
641+
}
642+
});
643+
644+
httpBatcher.flush();
645+
646+
$httpBackend.flush();
647+
});
648+
});
615649
});
616650
});
617651
}(angular, sinon));

0 commit comments

Comments
 (0)