function buildRequestFn(requests, config) {
    var boundary = httpBatchConfig.calculateBoundary(),
      httpConfig = {
        method: 'POST',
        url: config.batchEndpointUrl,
        cache: false,
        headers: config.batchRequestHeaders || {}
      },
      batchBody = [],
      urlInfo, i, request, header, relativeUrlParts, encodedRelativeUrl;

    httpConfig.headers[constants.contentType] = 'multipart/mixed; boundary=' + boundary;

    for (i = 0; i < requests.length; i += 1) {
      request = requests[i];
      urlInfo = getUrlInfo(request.url);

      batchBody.push(constants.doubleDash + boundary);
      if (config.batchPartRequestHeaders) {
        for (header in config.batchPartRequestHeaders) {
          if (config.batchPartRequestHeaders.hasOwnProperty(header)) {
            var currHeader = header + constants.colon + constants.singleSpace + config.batchPartRequestHeaders[header];
            if (header.toLowerCase() === "content-disposition" && config.uniqueRequestName !== null && config.uniqueRequestName !== undefined) {
              currHeader += constants.semiColon + constants.singleSpace + constants.requestName + config.uniqueRequestName + i;
            }
            batchBody.push(currHeader);
          }
        }
      }

      batchBody.push('Content-Type: application/http; msgtype=request', constants.emptyString);

      // 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] : '');

      batchBody.push(request.method + ' ' + encodedRelativeUrl + ' ' + constants.httpVersion);
      batchBody.push('Host: ' + urlInfo.host);

      for (header in request.headers) {
        batchBody.push(header + constants.colon + constants.singleSpace + request.headers[header]);
      }

      if (config.sendCookies === true && $document[0].cookie && $document[0].cookie.length > 0) {
        batchBody.push('Cookie: ' + $document[0].cookie);
      }

      batchBody.push(constants.emptyString);

      if (request.data) {
        batchBody.push(request.data);
      }

      batchBody.push(constants.emptyString);
    }

    batchBody.push(constants.doubleDash + boundary + constants.doubleDash);
    httpConfig.data = batchBody.join(constants.newline);
    return httpConfig;
  }
/**
   * Builds the single batch request from the given batch of pending requests.
   * Returns a standard angular httpConfig object that will be use to invoke the $http service.
   * See:
   * https://developers.google.com/storage/docs/json_api/v1/how-tos/batch
   * http://blogs.msdn.com/b/webdev/archive/2013/11/01/introducing-batch-support-in-web-api-and-web-api-odata.aspx
   *
   * @param requests - the collection of pending http request to build into a single http batch request.
   * @param config - the http batch config.
   * @returns {object} - a http config object.
   */
Builds the single batch request from the given batch of pending requests.
Returns a standard angular httpConfig object that will be use to invoke the $http service.

@param requests - the collection of pending http request to build into a single http batch request.
@param config - the http batch config.
@returns {object} - a http config object.
Builds the single batch request from the given batch of pending requests . Returns a standard angular httpConfig object that will be use to invoke the $http service . @param requests - the collection of pending http request to build into a single http batch request . @param config - the http batch config . @returns { object } - a http config object .
function buildRequestFn(requests, config) {
    var boundary = httpBatchConfig.calculateBoundary(),
      httpConfig = {
        method: 'POST',
        url: config.batchEndpointUrl,
        cache: false,
        headers: config.batchRequestHeaders || {}
      },
      batchBody = [],
      urlInfo, i, request, header, relativeUrlParts, encodedRelativeUrl;
    httpConfig.headers[constants.contentType] = 'multipart/mixed; boundary=' + boundary;
    for (i = 0; i < requests.length; i += 1) {
      request = requests[i];
      urlInfo = getUrlInfo(request.url);
      batchBody.push(constants.doubleDash + boundary);
      if (config.batchPartRequestHeaders) {
        for (header in config.batchPartRequestHeaders) {
          if (config.batchPartRequestHeaders.hasOwnProperty(header)) {
            var currHeader = header + constants.colon + constants.singleSpace + config.batchPartRequestHeaders[header];
            if (header.toLowerCase() === "content-disposition" && config.uniqueRequestName !== null && config.uniqueRequestName !== undefined) {
              currHeader += constants.semiColon + constants.singleSpace + constants.requestName + config.uniqueRequestName + i;
            }
            batchBody.push(currHeader);
          }
        }
      }
      batchBody.push('Content-Type: application/http; msgtype=request', constants.emptyString);
      relativeUrlParts = urlInfo.relativeUrl.split('?');
      encodedRelativeUrl = encodeURI(relativeUrlParts[0]) + (relativeUrlParts.length > 1 ? '?' + relativeUrlParts[1] : '');
      batchBody.push(request.method + ' ' + encodedRelativeUrl + ' ' + constants.httpVersion);
      batchBody.push('Host: ' + urlInfo.host);
      for (header in request.headers) {
        batchBody.push(header + constants.colon + constants.singleSpace + request.headers[header]);
      }
      if (config.sendCookies === true && $document[0].cookie && $document[0].cookie.length > 0) {
        batchBody.push('Cookie: ' + $document[0].cookie);
      }
      batchBody.push(constants.emptyString);
      if (request.data) {
        batchBody.push(request.data);
      }
      batchBody.push(constants.emptyString);
    }
    batchBody.push(constants.doubleDash + boundary + constants.doubleDash);
    httpConfig.data = batchBody.join(constants.newline);
    return httpConfig;
  }
function buildRequestFn ( requests , config ) { var boundary = httpBatchConfig . calculateBoundary ( ) , httpConfig = { method : 'POST' , url : config . batchEndpointUrl , cache : false , headers : config . batchRequestHeaders || { } } , batchBody = [ ] , urlInfo , i , request , header , relativeUrlParts , encodedRelativeUrl ; httpConfig . headers [ constants . contentType ] = 'multipart/mixed; boundary=' + boundary ; for ( i = 0 ; i < requests . length ; i += 1 ) { request = requests [ i ] ; urlInfo = getUrlInfo ( request . url ) ; batchBody . push ( constants . doubleDash + boundary ) ; if ( config . batchPartRequestHeaders ) { for ( header in config . batchPartRequestHeaders ) { if ( config . batchPartRequestHeaders . hasOwnProperty ( header ) ) { var currHeader = header + constants . colon + constants . singleSpace + config . batchPartRequestHeaders [ header ] ; if ( header . toLowerCase ( ) === "content-disposition" && config . uniqueRequestName !== null && config . uniqueRequestName !== undefined ) { currHeader += constants . semiColon + constants . singleSpace + constants . requestName + config . uniqueRequestName + i ; } batchBody . push ( currHeader ) ; } } } batchBody . push ( 'Content-Type: application/http; msgtype=request' , constants . emptyString ) ; relativeUrlParts = urlInfo . relativeUrl . split ( '?' ) ; encodedRelativeUrl = encodeURI ( relativeUrlParts [ 0 ] ) + ( relativeUrlParts . length > 1 ? '?' + relativeUrlParts [ 1 ] : '' ) ; batchBody . push ( request . method + ' ' + encodedRelativeUrl + ' ' + constants . httpVersion ) ; batchBody . push ( 'Host: ' + urlInfo . host ) ; for ( header in request . headers ) { batchBody . push ( header + constants . colon + constants . singleSpace + request . headers [ header ] ) ; } if ( config . sendCookies === true && $document [ 0 ] . cookie && $document [ 0 ] . cookie . length > 0 ) { batchBody . push ( 'Cookie: ' + $document [ 0 ] . cookie ) ; } batchBody . push ( constants . emptyString ) ; if ( request . data ) { batchBody . push ( request . data ) ; } batchBody . push ( constants . emptyString ) ; } batchBody . push ( constants . doubleDash + boundary + constants . doubleDash ) ; httpConfig . data = batchBody . join ( constants . newline ) ; return httpConfig ; }
Builds the single batch request from the given batch of pending requests.
Builds the single batch request from the given batch of pending requests .
// 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