diff --git a/.jshintrc b/.jshintrc index 2822d9d..06d7269 100644 --- a/.jshintrc +++ b/.jshintrc @@ -18,7 +18,7 @@ "indent": 2, "globals": { "document": true, - "window": true, + "global": true, "angular": true, "sinon": true, "module": true, diff --git a/dist/angular-http-batch.js b/dist/angular-http-batch.js index f721d9e..38c9851 100644 --- a/dist/angular-http-batch.js +++ b/dist/angular-http-batch.js @@ -1,13 +1,15 @@ /* - * angular-http-batcher - v1.12.0 - 2015-10-12 + * angular-http-batcher - v1.12.0 - 2016-02-16 * https://github.com/jonsamwell/angular-http-batcher - * Copyright (c) 2015 Jon Samwell + * Copyright (c) 2016 Jon Samwell */ -(function (window, angular) { +(function (angular) { 'use strict'; -window.ahb = { - name: 'jcs.angular-http-batch' +var global = { + ahb: { + name: 'jcs.angular-http-batch' + } }; /** @@ -17,7 +19,7 @@ window.ahb = { * @description * The main module which holds everything together. */ -angular.module(window.ahb.name, []); +angular.module(global.ahb.name, []); function HttpBatchConfigFn() { var allowedBatchDomains = [], @@ -173,7 +175,7 @@ function HttpBatchConfigFn() { ]; } -angular.module(window.ahb.name).provider('httpBatchConfig', HttpBatchConfigFn); +angular.module(global.ahb.name).provider('httpBatchConfig', HttpBatchConfigFn); /** * @@ -192,7 +194,7 @@ function HttpBatchResponseData(request, statusCode, statusText, data, headers) { this.headers = headers; } -window.ahb.HttpBatchResponseData = HttpBatchResponseData; +global.ahb.HttpBatchResponseData = HttpBatchResponseData; function HttpBatchAdapter($document, $window, httpBatchConfig) { var self = this, @@ -260,7 +262,14 @@ function HttpBatchAdapter($document, $window, httpBatchConfig) { // angular would have already encoded the parameters *if* the dev passed them in via the params parameter to $http // so we only need to url encode the url not the query string part relativeUrlParts = urlInfo.relativeUrl.split('?'); - encodedRelativeUrl = encodeURI(relativeUrlParts[0]) + (relativeUrlParts.length > 1 ? '?' + relativeUrlParts[1] : ''); + // do a very basic check to see if query strings are encoded as dev might + // have just added them to the url and not passed them in via the params config param to $http + if (relativeUrlParts.length > 1 && (/%[A-F0-9]{2}/gi).test(relativeUrlParts[1]) === false) { + // chances are they are not encoded so encode them + encodedRelativeUrl = encodeURI(urlInfo.relativeUrl); + } else { + encodedRelativeUrl = encodeURI(relativeUrlParts[0]) + (relativeUrlParts.length > 1 ? '?' + relativeUrlParts[1] : ''); + } batchBody.push(request.method + ' ' + encodedRelativeUrl + ' ' + constants.httpVersion); batchBody.push('Host: ' + urlInfo.host); @@ -450,7 +459,7 @@ function HttpBatchAdapter($document, $window, httpBatchConfig) { } result.headers[constants.contentType] = result.contentType; - return new window.ahb.HttpBatchResponseData(request, result.statusCode, result.statusText, result.data, result.headers); + return new global.ahb.HttpBatchResponseData(request, result.statusCode, result.statusText, result.data, result.headers); } } @@ -460,7 +469,7 @@ HttpBatchAdapter.$inject = [ 'httpBatchConfig' ]; -angular.module(window.ahb.name).service('httpBatchAdapter', HttpBatchAdapter); +angular.module(global.ahb.name).service('httpBatchAdapter', HttpBatchAdapter); function NodeJsMultiFetchAdapter() { var self = this; @@ -526,7 +535,7 @@ function NodeJsMultiFetchAdapter() { request = requests[i]; dataPart = responseData[i.toString()]; - batchResponses.push(new window.ahb.HttpBatchResponseData( + batchResponses.push(new global.ahb.HttpBatchResponseData( request, dataPart.statusCode, '', @@ -547,7 +556,7 @@ function NodeJsMultiFetchAdapter() { } } -angular.module(window.ahb.name).service('nodeJsMultiFetchAdapter', NodeJsMultiFetchAdapter); +angular.module(global.ahb.name).service('nodeJsMultiFetchAdapter', NodeJsMultiFetchAdapter); function convertHeadersToString(headers) { var property, @@ -693,7 +702,7 @@ HttpBatcherFn.$inject = [ 'nodeJsMultiFetchAdapter' ]; -angular.module(window.ahb.name).service('httpBatcher', HttpBatcherFn); +angular.module(global.ahb.name).service('httpBatcher', HttpBatcherFn); function HttpBackendDecorator($delegate, httpBatcher) { var $httpBackendFn = function (method, url, post, callback, headers, timeout, withCredentials, responseType) { @@ -744,6 +753,6 @@ ProviderDecoratorFn.$inject = [ '$provide' ]; -angular.module(window.ahb.name).config(ProviderDecoratorFn); +angular.module(global.ahb.name).config(ProviderDecoratorFn); -}(window, angular)); +}(angular)); diff --git a/dist/angular-http-batch.min.js b/dist/angular-http-batch.min.js index d6de283..2abdff6 100644 --- a/dist/angular-http-batch.min.js +++ b/dist/angular-http-batch.min.js @@ -1,5 +1,5 @@ /* - * angular-http-batcher - v1.12.0 - 2015-10-12 + * angular-http-batcher - v1.12.0 - 2016-02-16 * https://github.com/jonsamwell/angular-http-batcher - * Copyright (c) 2015 Jon Samwell;*/ -!function(a,b){"use strict";function c(){var a=[],c="httpBatchAdapter",d={maxBatchedRequestPerCall:10,minimumBatchSize:2,batchRequestCollectionDelay:100,ignoredVerbs:["head"],sendCookies:!1,enabled:!0,adapter:c,uniqueRequestName:null};this.setAllowedBatchEndpoint=function(e,f,g){var h=b.copy(d);void 0!==g&&(b.forEach(g,function(a,b){h[b]=a}),b.forEach(h.ignoredVerbs,function(a,b){h.ignoredVerbs[b]=a.toLowerCase()})),h.serviceUrl=e,h.batchEndpointUrl=f,h.adapter=h.adapter||c,a.push(h)},this.getBatchConfig=function(b){var c,d;for(d=0;d-1));d+=1)c=void 0;return c},this.canBatchCall=function(a,b){var c=this.getBatchConfig(a),d=c?c.canBatchRequest:void 0,e=!1;return c&&c.enabled===!0&&(e=d?d(a,b):c.batchEndpointUrl!==a&&-1===a.indexOf(c.batchEndpointUrl)&&-1===c.ignoredVerbs.indexOf(b.toLowerCase())),e},this.calculateBoundary=function(){return(new Date).getTime().toString()},this.$get=[function(){return this}]}function d(a,b,c,d,e){this.request=a,this.statusCode=b,this.statusText=c,this.data=d,this.headers=e}function e(c,d,e){function f(a,b){var d,f,g,h,i,k,l=e.calculateBoundary(),m={method:"POST",url:b.batchEndpointUrl,cache:!1,headers:b.batchRequestHeaders||{}},n=[];for(m.headers[p.contentType]="multipart/mixed; boundary="+l,f=0;f1?"?"+i[1]:""),n.push(g.method+" "+k+" "+p.httpVersion),n.push("Host: "+d.host);for(h in g.headers)n.push(h+p.colon+p.singleSpace+g.headers[h]);b.sendCookies===!0&&c[0].cookie&&c[0].cookie.length>0&&n.push("Cookie: "+c[0].cookie),n.push(p.emptyString),g.data&&n.push(g.data),n.push(p.emptyString)}return n.push(p.doubleDash+l+p.doubleDash),m.data=n.join(p.newline),m}function g(a,b,c){var d,e,f=[],g=k(b.headers()["content-type"]),h=b.data.split(p.doubleDash+g+p.newline),i=0;for(d=0;d-1||a.indexOf("../")>-1){var h=document.createElement("a");h.href=a,a=h.href}return a.indexOf("://")>-1?(f=a.indexOf("://")+3,g=a.slice(f).split(p.forwardSlash),b=a.substring(0,f),c=g[0],e=function(){return delete g[0],g.join(p.forwardSlash)}()):(e=a,b=d.location.protocol,c=d.location.host),{protocol:b,host:c,relativeUrl:e}}function k(a){var b="boundary=",c=a.indexOf(b),d=a.indexOf(";",c),e=a.substring(c+b.length,d>0?d:a.length);return e=e.replace(/"/g,p.emptyString)}function l(a){return"string"==typeof a?a.replace(")]}',\n",""):a}function m(a,c){var d=c;return a=a.toLowerCase(),a.indexOf("json")>-1&&(c=l(c),d=b.fromJson(c)),d}function n(b,c,d){var e,f,g,h,j,k,l=b.split(p.newline),n={headers:{}},o=!1;for(f=0;f1&&(c+="?"+encodeURIComponent(f[1])),d>0&&(g.url+="&"),g.url+=d.toString()+"="+c;return g}function c(b,c){var d,e,f,g=[],h=c.data;for(d=0;d=this.config.maxBatchedRequestPerCall&&this.flush(),!0}function j(){var a=this,c=a.getAdapter(),d=c.buildRequest(a.requests,a.config);a.sendCallback(),a.$injector.get("$http")(d).then(function(d){var e=c.parseResponse(a.requests,d,a.config);b.forEach(e,function(a){a.request.callback(a.statusCode,a.data,g(a.headers),a.statusText)})},function(c){b.forEach(a.requests,function(a){a.callback(c.statusCode,c.data,c.headers,c.statusText)})})}function k(){this.$timeout.cancel(this.currentTimeoutToken),this.currentTimeoutToken=void 0,this.send()}function l(a,c,d,e,f){var g=this;this.$injector=a,this.$timeout=c,this.adapters=d,this.config=e,this.sendCallback=f,this.requests=[],this.currentTimeoutToken=c(function(){g.currentTimeoutToken=void 0,g.requests.length-1));d+=1)c=void 0;return c},this.canBatchCall=function(a,b){var c=this.getBatchConfig(a),d=c?c.canBatchRequest:void 0,e=!1;return c&&c.enabled===!0&&(e=d?d(a,b):c.batchEndpointUrl!==a&&-1===a.indexOf(c.batchEndpointUrl)&&-1===c.ignoredVerbs.indexOf(b.toLowerCase())),e},this.calculateBoundary=function(){return(new Date).getTime().toString()},this.$get=[function(){return this}]}function c(a,b,c,d,e){this.request=a,this.statusCode=b,this.statusText=c,this.data=d,this.headers=e}function d(b,c,d){function e(a,c){var e,f,g,h,j,k,l=d.calculateBoundary(),m={method:"POST",url:c.batchEndpointUrl,cache:!1,headers:c.batchRequestHeaders||{}},n=[];for(m.headers[p.contentType]="multipart/mixed; boundary="+l,f=0;f1&&/%[A-F0-9]{2}/gi.test(j[1])===!1?encodeURI(e.relativeUrl):encodeURI(j[0])+(j.length>1?"?"+j[1]:""),n.push(g.method+" "+k+" "+p.httpVersion),n.push("Host: "+e.host);for(h in g.headers)n.push(h+p.colon+p.singleSpace+g.headers[h]);c.sendCookies===!0&&b[0].cookie&&b[0].cookie.length>0&&n.push("Cookie: "+b[0].cookie),n.push(p.emptyString),g.data&&n.push(g.data),n.push(p.emptyString)}return n.push(p.doubleDash+l+p.doubleDash),m.data=n.join(p.newline),m}function f(a,b,c){var d,e,f=[],g=j(b.headers()["content-type"]),h=b.data.split(p.doubleDash+g+p.newline),i=0;for(d=0;d-1||a.indexOf("../")>-1){var h=document.createElement("a");h.href=a,a=h.href}return a.indexOf("://")>-1?(f=a.indexOf("://")+3,g=a.slice(f).split(p.forwardSlash),b=a.substring(0,f),d=g[0],e=function(){return delete g[0],g.join(p.forwardSlash)}()):(e=a,b=c.location.protocol,d=c.location.host),{protocol:b,host:d,relativeUrl:e}}function j(a){var b="boundary=",c=a.indexOf(b),d=a.indexOf(";",c),e=a.substring(c+b.length,d>0?d:a.length);return e=e.replace(/"/g,p.emptyString)}function k(a){return"string"==typeof a?a.replace(")]}',\n",""):a}function l(b,c){var d=c;return b=b.toLowerCase(),b.indexOf("json")>-1&&(c=k(c),d=a.fromJson(c)),d}function m(a,b,c){var d,e,f,g,i,j,k=a.split(p.newline),m={headers:{}},n=!1;for(e=0;e1&&(c+="?"+encodeURIComponent(f[1])),d>0&&(g.url+="&"),g.url+=d.toString()+"="+c;return g}function b(a,b){var c,d,e,f=[],g=b.data;for(c=0;c=this.config.maxBatchedRequestPerCall&&this.flush(),!0}function i(){var b=this,c=b.getAdapter(),d=c.buildRequest(b.requests,b.config);b.sendCallback(),b.$injector.get("$http")(d).then(function(d){var e=c.parseResponse(b.requests,d,b.config);a.forEach(e,function(a){a.request.callback(a.statusCode,a.data,f(a.headers),a.statusText)})},function(c){a.forEach(b.requests,function(a){a.callback(c.statusCode,c.data,c.headers,c.statusText)})})}function j(){this.$timeout.cancel(this.currentTimeoutToken),this.currentTimeoutToken=void 0,this.send()}function k(b,c,d,e,f){var g=this;this.$injector=b,this.$timeout=c,this.adapters=d,this.config=e,this.sendCallback=f,this.requests=[],this.currentTimeoutToken=c(function(){g.currentTimeoutToken=void 0,g.requests.length-->