var http = require('http')
  , url = require('url')
  , express = require('express')
  , rest = express()
  , path = require('path')
  , server = http.createServer(rest)
  , ap = require('argparse').ArgumentParser
  , colors = require('colors')
  , appium = require('./app/appium')
  , parser = require('./app/parser');

rest.configure(function() {
  rest.use(express.favicon());
  rest.use(express.static(path.join(__dirname, '/app/static')));
  rest.use(express.logger('dev'));
  rest.use(express.bodyParser());
  rest.use(express.methodOverride());
  rest.use(rest.router);
});

// Parse the command line arguments
var args = parser().parseArgs();

// Instantiate the appium instance
var appium = appium(args.app, args.UDID, args.verbose);
// Hook up REST http interface
appium.attachTo(rest);

// Start the web server that receives all the commands
server.listen(args.port, args.address, function() {
  var logMessage = "Appium REST http interface listener started on "+args.address+":"+args.port;
  console.log(logMessage.cyan);
});

@@ -342,16 +342,329 @@
 ion() %7B%0A
+  var bodyParser = express.bodyParser()%0A    , parserWrap = function(req, res, next) %7B%0A        // wd.js sends us http POSTs with empty body which will make bodyParser fail.%0A        if (parseInt(req.get('content-length'), 10) %3C= 0) %7B%0A          return next();%0A        %7D%0A        bodyParser(req, res, next);%0A      %7D;%0A%0A
   rest.u
@@ -682,24 +682,24 @@
 favicon());%0A
-
   rest.use(e
@@ -797,36 +797,26 @@
 est.use(
-express.bodyP
+p
 arser
-()
+Wrap
 );%0A  res

Deal with invalid http POST more gracefully.