Skip to content

Commit

Permalink
refactor: use explicit variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
honzajavorek committed Apr 4, 2019
1 parent 937da79 commit 9a1d88a
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions lib/performRequest.js
Expand Up @@ -5,7 +5,7 @@ const defaultLogger = require('./logger');


/**
* Performs the HTTP request as described in the 'transaction.request' object.
* Performs the HTTP request as described in the 'transaction.request' object
*
* In future we should introduce a 'real' request object as well so user has
* access to the modifications made on the way.
Expand All @@ -19,9 +19,7 @@ const defaultLogger = require('./logger');
* @param {Function} callback
*/
function performRequest(uri, transactionReq, options, callback) {
if (typeof options === 'function') {
[options, callback] = [{}, options];
}
if (typeof options === 'function') { [options, callback] = [{}, options]; }
const logger = options.logger || defaultLogger;
const request = options.request || defaultRequest;

Expand All @@ -40,12 +38,12 @@ function performRequest(uri, transactionReq, options, callback) {
logger.debug(`Performing ${protocol} request to the server under test: `
+ `${httpOptions.method} ${httpOptions.uri}`);

request(httpOptions, (error, res, resBody) => {
request(httpOptions, (error, response, responseBody) => {
logger.debug(`Handling ${protocol} response from the server under test`);
if (error) {
callback(error);
} else {
callback(null, createTransactionResponse(res, resBody));
callback(null, createTransactionResponse(response, responseBody));
}
});
} catch (error) {
Expand Down Expand Up @@ -122,13 +120,13 @@ function normalizeContentLengthHeader(headers, body, options = {}) {
* Real transaction response object factory. Serializes binary responses
* to string using Base64 encoding.
*
* @param {Object} res Node.js HTTP response
* @param {Object} response Node.js HTTP response
* @param {Buffer} body HTTP response body as Buffer
*/
function createTransactionResponse(res, body) {
function createTransactionResponse(response, body) {
const transactionRes = {
statusCode: res.statusCode,
headers: Object.assign({}, res.headers),
statusCode: response.statusCode,
headers: Object.assign({}, response.headers),
};
if (Buffer.byteLength(body || '')) {
transactionRes.bodyEncoding = detectBodyEncoding(body);
Expand Down

0 comments on commit 9a1d88a

Please sign in to comment.