diff --git a/dist/angular-http-batch.js b/dist/angular-http-batch.js index f721d9e..fd11887 100644 --- a/dist/angular-http-batch.js +++ b/dist/angular-http-batch.js @@ -1,7 +1,7 @@ /* - * angular-http-batcher - v1.12.0 - 2015-10-12 + * angular-http-batcher - v1.12.0 - 2017-02-15 * https://github.com/jonsamwell/angular-http-batcher - * Copyright (c) 2015 Jon Samwell + * Copyright (c) 2017 Jon Samwell */ (function (window, angular) { 'use strict'; @@ -260,7 +260,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); @@ -587,8 +594,12 @@ function addRequestFn(request) { function sendFn() { var self = this, - adapter = self.getAdapter(), - httpBatchConfig = adapter.buildRequest(self.requests, self.config); + adapter = self.getAdapter(); + if (adapter.hasOwnProperty('send')) { + return adapter.send.apply(this); + } + + var httpBatchConfig = adapter.buildRequest(self.requests, self.config); self.sendCallback(); self.$injector.get('$http')(httpBatchConfig).then(function (response) { diff --git a/dist/angular-http-batch.min.js b/dist/angular-http-batch.min.js index d6de283..97e969f 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 - 2017-02-15 * 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&&a.indexOf(c.batchEndpointUrl)===-1&&c.ignoredVerbs.indexOf(b.toLowerCase())===-1),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&&/%[A-F0-9]{2}/gi.test(i[1])===!1?encodeURI(d.relativeUrl):encodeURI(i[0])+(i.length>1?"?"+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();if(c.hasOwnProperty("send"))return c.send.apply(this);var 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