lib/performRequest.js
function normalizeContentLengthHeader(headers, body, options = {}) {
  const logger = options.logger || defaultLogger;

  const modifiedHeaders = Object.assign({}, headers);
  const calculatedValue = Buffer.byteLength(body);
  const name = caseless(modifiedHeaders).has('Content-Length');
  if (name) {
    const value = parseInt(modifiedHeaders[name], 10);
    if (value !== calculatedValue) {
      modifiedHeaders[name] = `${calculatedValue}`;
      logger.warn(`Specified Content-Length header is ${value}, but the real `
        + `body length is ${calculatedValue}. Using ${calculatedValue} instead.`);
    }
  } else {
    modifiedHeaders['Content-Length'] = `${calculatedValue}`;
  }
  return modifiedHeaders;
}
function normalizeContentLengthHeader(headers, body, options = {}) {
  const logger = options.logger || defaultLogger;

  const modifiedHeaders = Object.assign({}, headers);
  const calculatedValue = Buffer.byteLength(body);
  const name = caseless(modifiedHeaders).has('Content-Length');
  if (name) {
    const value = parseInt(modifiedHeaders[name], 10);
    if (value !== calculatedValue) {
      modifiedHeaders[name] = `${calculatedValue}`;
      logger.warn(`Specified Content-Length header is ${value}, but the real `
        + `body length is ${calculatedValue}. Using ${calculatedValue} instead.`);
    }
  } else {
    modifiedHeaders['Content-Length'] = `${calculatedValue}`;
  }
  return modifiedHeaders;
}
function normalizeContentLengthHeader ( headers , body , options = { } ) { const logger = options . logger || defaultLogger ; const modifiedHeaders = Object . assign ( { } , headers ) ; const calculatedValue = Buffer . byteLength ( body ) ; const name = caseless ( modifiedHeaders ) . has ( 'Content-Length' ) ; if ( name ) { const value = parseInt ( modifiedHeaders [ name ] , 10 ) ; if ( value !== calculatedValue ) { modifiedHeaders [ name ] = ` ${ calculatedValue } ` ; logger . warn ( ` ${ value } ` + ` ${ calculatedValue } ${ calculatedValue } ` ) ; } } else { modifiedHeaders [ 'Content-Length' ] = ` ${ calculatedValue } ` ; } return modifiedHeaders ; }
Detects an existing Content-Length header and overrides the user-provided
header value in case it's out of sync with the real length of the body.

@param {Object} headers HTTP request headers
@param {Buffer} body HTTP request body
@param {Object} [options]
@param {Object} [options.logger] Custom logger
Detects an existing Content - Length header and overrides the user - provided header value in case it s out of sync with the real length of the body .