Skip to content

Commit

Permalink
made soda use http.request() istead of the deprecated http.createClie…
Browse files Browse the repository at this point in the history
…nt()
  • Loading branch information
Manuel Goerlich committed Sep 19, 2012
1 parent 146e29d commit 053c40b
Showing 1 changed file with 33 additions and 30 deletions.
63 changes: 33 additions & 30 deletions lib/soda/client.js
Expand Up @@ -14,14 +14,14 @@ var http = require('http')


/** /**
* Initialize a `Client` with the given `options`. * Initialize a `Client` with the given `options`.
* *
* Options: * Options:
* *
* - `host` Hostname defaulting to localhost * - `host` Hostname defaulting to localhost
* - `port` Port number defaulting to 4444 * - `port` Port number defaulting to 4444
* - `browser` Browser name * - `browser` Browser name
* - `url` URL string * - `url` URL string
* *
* @params {Object} options * @params {Object} options
* @api public * @api public
*/ */
Expand Down Expand Up @@ -83,42 +83,41 @@ Client.prototype.session = function(fn){
Client.prototype.command = function(cmd, args, fn){ Client.prototype.command = function(cmd, args, fn){
this.emit('command', cmd, args); this.emit('command', cmd, args);


// HTTP client
var client = http.createClient(this.port, this.host);

// Path construction // Path construction
var path = this.commandPath(cmd, args); var path = this.commandPath(cmd, args);


// Assemble Request Options as far as possible
var reqOptions = {
host: this.host,
port: this.port,
path: path,
method: 'GET',
headers: { Host: this.host + (this.port ? ':' + this.port : '') }
}

This comment has been minimized.

Copy link
@alienintheheights

alienintheheights Jan 30, 2013

missing semi-colon at line 96. Fixed locally, but this should get updated for those of us using jslint against everything.


var req; var req;

// Selenium RC can support POST request: http://svn.openqa.org/fisheye/changelog/selenium-rc/?cs=1898, // Selenium RC can support POST request: http://svn.openqa.org/fisheye/changelog/selenium-rc/?cs=1898,
// we need to switch to use POST if the URL's is too long (Below I use the Internet Explorer's limit). // we need to switch to use POST if the URL's is too long (Below I use the Internet Explorer's limit).
// See also: http://jira.openqa.org/browse/SRC-50 // See also: http://jira.openqa.org/browse/SRC-50
if (path.length > 2048 && (this.host + path ).length > 2083) { if (path.length > 2048 && (this.host + path ).length > 2083) {
postData = this.commandPath(cmd, args).replace('/selenium-server/driver/?', ""); var postData = this.commandPath(cmd, args).replace('/selenium-server/driver/?', "");
req = client.request('POST'
, path reqOptions.path = path;
, { Host: this.host + (this.port ? ':' + this.port : '') reqOptions.method = 'POST';
, 'Content-Length': postData.length reqOptions.headers['Content-Length'] = postData.length;
, 'Content-Type': 'application/x-www-form-urlencoded' reqOptions.headers['Content-Type'] = 'application/x-www-form-urlencoded';
});

req.write(postData);
} else {
req = client.request('GET'
, path
, { Host: this.host + (this.port ? ':' + this.port : '') });
} }

req.on('response', function(res){ req = http.request(reqOptions, function(res) {
res.body = ''; res.body = '';
res.setEncoding('utf8'); res.setEncoding('utf8');
res.on('data', function(chunk){ res.body += chunk; }); res.on('data', function(chunk){ res.body += chunk; });
res.on('end', function(){ res.on('end', function(){
if (res.body.indexOf('ERROR') === 0 || if (res.body.indexOf('ERROR') === 0 ||
res.body.indexOf('Timed out after ') === 0) { res.body.indexOf('Timed out after ') === 0) {
var err = res.body.replace(/^ERROR: */, ''); var err = res.body.replace(/^ERROR: */, '');
err = cmd + '(' + args.join(', ') + '): ' + err; err = cmd + '(' + args.join(', ') + '): ' + err;
fn(new Error(err), res.body, res); fn(new Error(err), res.body, res);
} else { } else {
if (res.body.indexOf('OK') === 0) { if (res.body.indexOf('OK') === 0) {
Expand All @@ -127,9 +126,14 @@ Client.prototype.command = function(cmd, args, fn){
fn(null, res.body, res); fn(null, res.body, res);
} }
}); });
return this;
}); });

if(postData) {
req.write(postData);
}

req.end(); req.end();
return this;
}; };


/** /**
Expand Down Expand Up @@ -190,7 +194,7 @@ Client.prototype.__defineGetter__('chain', function(){
*/ */


Client.prototype.end = function(fn){ Client.prototype.end = function(fn){
this._done = function(){this.queue = []; return fn.apply(this, arguments)}; this._done = function(){this.queue = null; return fn.apply(this, arguments)};

This comment has been minimized.

Copy link
@alienintheheights

alienintheheights Jan 30, 2013

this undoes the previous fix by pacovell. See 81a684f

this.queue.shift()(); this.queue.shift()();
}; };


Expand Down Expand Up @@ -262,7 +266,7 @@ exports.createClient = function(options){


/** /**
* Command names. * Command names.
* *
* @type Array * @type Array
*/ */


Expand Down Expand Up @@ -362,7 +366,7 @@ exports.commands = [


/** /**
* Accessor names. * Accessor names.
* *
* @type Array * @type Array
*/ */


Expand Down Expand Up @@ -423,13 +427,12 @@ exports.accessors = [
, 'PromptPresent' , 'PromptPresent'
, 'SomethingSelected' , 'SomethingSelected'
, 'TextPresent' , 'TextPresent'
, 'TextNotPresent'

This comment has been minimized.

Copy link
@paulbjensen

paulbjensen Nov 25, 2012

Hi, was this line supposed to be deleted in this commit? It came from this pull request:

3a9a5fb

This comment has been minimized.

Copy link
@mgoerlich-dev

mgoerlich-dev via email Nov 26, 2012

This comment has been minimized.

Copy link
@paulbjensen

paulbjensen Nov 26, 2012

ok, someone should add it back in /cc @guille

This comment has been minimized.

Copy link
@rauchg

rauchg Nov 26, 2012

Contributor

haha that was random

This comment has been minimized.

Copy link
@rauchg

rauchg Nov 26, 2012

Contributor
, 'Visible' , 'Visible'
]; ];


/** /**
* Generate commands via accessors. * Generate commands via accessors.
* *
* All accessors get prefixed with: * All accessors get prefixed with:
* *
* - get * - get
Expand Down

0 comments on commit 053c40b

Please sign in to comment.