<commit_before>/**
 * RequestHandler 
 */

var http       = require('http'),
    log        = require('./log'),
    extend     = require('./extend'),
    errorCodes = require('./errorCodes');

var RequestHandler = module.exports = function(options) {

    'use strict';

    this.sessionID      = null;
    this.startPath      = '/wd/hub';

    this.defaultOptions = {
        host: options.host || 'localhost',
        port: options.port || 4444,
        method: 'POST',
        protocol: 'http:'
    };

    // set auth from user and password configs
    if(options.user && options.pwd) {
        options.auth = options.user + ':' + options.pwd;
        delete options.user;
        delete options.pwd;
    }

    this.defaultOptions = extend(this.defaultOptions, options);

    this.defaultHeaders = {
        'Connection': 'keep-alive',
        'Accept': 'application/json;charset=utf-8',
        'content-type': 'application/json;charset=utf-8'
    };

    /**
     * creates a http request with its given options and send the protocol
     * command to the webdriver server
     * 
     * @param  {Object}   requestOptions  defines url, method and other request options
     * @param  {Object}   data            contains request data<commit_msg>rename option attribute from pwd to key<commit_after>/**
 * RequestHandler 
 */

var http       = require('http'),
    log        = require('./log'),
    extend     = require('./extend'),
    errorCodes = require('./errorCodes');

var RequestHandler = module.exports = function(options) {

    'use strict';

    this.sessionID      = null;
    this.startPath      = '/wd/hub';

    this.defaultOptions = {
        host: options.host || 'localhost',
        port: options.port || 4444,
        method: 'POST',
        protocol: 'http:'
    };

    // rename options var key
    if(options.key) {
        options.pwd = options.key;
        delete options.key;
    }

    // set auth from user and password configs
    if(options.user && options.pwd) {
        options.auth = options.user + ':' + options.pwd;
        delete options.user;
        delete options.pwd;
    }

    this.defaultOptions = extend(this.defaultOptions, options);

    this.defaultHeaders = {
        'Connection': 'keep-alive',
        'Accept': 'application/json;charset=utf-8',
        'content-type': 'application/json;charset=utf-8'
    };

    /**
     * creates a http request with its given options and send the protocol
     * command to the webdriver server
     * 
     * @param  {Object}   requestOptions  defines url, method and other request options
     * @param  {Object}   data            contains request data
{'fraction_non_alphanumeric': 0.12641509433962264, 'fraction_numerical': 0.004528301886792453, 'mean_word_length': 2.236874236874237, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1047307', 'n_tokens_mistral': 761, 'n_tokens_neox': 737, 'n_words': 196}