diff --git a/lib/server/controller.js b/lib/server/controller.js index 39a480fd5..6c96e5848 100644 --- a/lib/server/controller.js +++ b/lib/server/controller.js @@ -50,7 +50,7 @@ exports.sessionBeforeFilter = function (req, res, next) { // if we don't actually have a valid session, respond with an error if (sessId && (!req.device || req.appium.sessionId !== sessId)) { safely(req, function () { - res.send(404, {sessionId: null, status: status.codes.NoSuchDriver.code, value: ''}); + res.status(404).send({sessionId: null, status: status.codes.NoSuchDriver.code, value: ''}); }); } else { next(); @@ -172,7 +172,7 @@ exports.createSession = function (req, res) { var next = function (reqHost, sessionId) { safely(req, function () { res.set('Location', "http://" + reqHost + "/wd/hub/session/" + sessionId); - res.send(303); + res.status(303).send("Appium session started with sessionId " + sessionId); }); }; if (req.appium.preLaunched && req.appium.sessionId) { @@ -953,8 +953,8 @@ exports.executeMobileMethod = function (req, res, cmd) { if (args.length) { if (args.length !== 1) { safely(req, function () { - res.send(400, "Mobile methods only take one parameter, which is a " + - "hash of named parameters to send to the method"); + res.status(400).send("Mobile methods only take one parameter, which is a " + + "hash of named parameters to send to the method"); }); } else { params = args[0]; @@ -1047,7 +1047,7 @@ exports.receiveAsyncResponse = function (req, res) { var asyncResponse = req.body; req.device.receiveAsyncResponse(asyncResponse); safely(req, function () { - res.send(200, 'OK'); + res.sendStatus(200); }); }; @@ -1113,7 +1113,7 @@ exports.unknownCommand = function (req, res) { logger.debug("Responding to client that we did not find a valid resource"); safely(req, function () { res.set('Content-Type', 'text/plain'); - res.send(404, "That URL did not map to a valid JSONWP resource"); + res.status(404).send("That URL did not map to a valid JSONWP resource"); }); }; diff --git a/lib/server/helpers.js b/lib/server/helpers.js index 967cbc011..d44a2eb19 100644 --- a/lib/server/helpers.js +++ b/lib/server/helpers.js @@ -22,7 +22,7 @@ module.exports.allowCrossDomain = function (req, res, next) { if ('OPTIONS' === req.method) { safely(req, function () { - res.send(200); + res.sendStatus(200); }); } else { next(); @@ -39,7 +39,7 @@ module.exports.winstonStream = { module.exports.catchAllHandler = function (e, req, res, next) { safely(req, function () { - res.send(500, { + res.status(500).send({ status: status.codes.UnknownError.code , value: "ERROR running Appium command: " + e.message }); diff --git a/lib/server/proxy.js b/lib/server/proxy.js index 25c29df75..7ff02ff7a 100644 --- a/lib/server/proxy.js +++ b/lib/server/proxy.js @@ -77,7 +77,7 @@ module.exports.doProxy = function (req, res) { safely(req, function () { res.headers = response.headers; res.set('Content-Type', response.headers['content-type']); - res.send(response.statusCode, body); + res.status(response.statusCode).send(body); }); }); }; diff --git a/lib/server/responses.js b/lib/server/responses.js index eb88e9d4c..9ab6c30e4 100644 --- a/lib/server/responses.js +++ b/lib/server/responses.js @@ -24,7 +24,7 @@ var notImplementedInThisContext = function (req, res) { logger.debug("Responding to client that a method is not implemented " + "in this context"); safely(req, function () { - res.send(501, { + res.status(501).send({ status: status.codes.UnknownError.code , sessionId: getSessionId(req) , value: { @@ -66,7 +66,7 @@ var respondError = exports.respondError = function (req, res, statusObj, value) response.sessionId = getSessionId(req, response); logger.debug("Responding to client with error: " + JSON.stringify(response)); safely(req, function () { - res.send(500, response); + res.status(500).send(response); }); }; @@ -86,7 +86,7 @@ var respondSuccess = exports.respondSuccess = function (req, res, value, sid) { res.jsonResp = JSON.stringify(printResponse); logger.debug("Responding to client with success: " + res.jsonResp); safely(req, function () { - res.send(response); + res.status(200).send(response); }); }; @@ -139,7 +139,7 @@ exports.checkMissingParams = function (req, res, params, strict) { var missingList = JSON.stringify(missingParamNames); logger.debug("Missing params for request: " + missingList); safely(req, function () { - res.send(400, "Missing parameters: " + missingList); + res.status(400).send("Missing parameters: " + missingList); }); return false; } else { @@ -150,7 +150,7 @@ exports.checkMissingParams = function (req, res, params, strict) { var notYetImplemented = exports.notYetImplemented = function (req, res) { logger.debug("Responding to client that a method is not implemented"); safely(req, function () { - res.send(501, { + res.status(501).send({ status: status.codes.UnknownError.code , sessionId: getSessionId(req) , value: { diff --git a/test/functional/dynamic-app/code-injector.js b/test/functional/dynamic-app/code-injector.js index 6c2c3da91..ad4f063c8 100644 --- a/test/functional/dynamic-app/code-injector.js +++ b/test/functional/dynamic-app/code-injector.js @@ -21,7 +21,7 @@ CodeInjector.prototype.start = function () { // caching code and returning 200 this.code = req.body.code; console.log('code injector is saving code. code -->', this.code); - res.send(200); + res.sendStatus(200); }.bind(this)); this.app.get('/code', function (req, res) {