Use tornado as WSGI server, refactor web plugin

- Encapsulate various setup* functions in a WebApplication class
- Make both *nix and windows 'run' variants static methods on
  WebCommands
- Move websocket endpoint from a separate port to a '/ws' endpoint,
  since we can now run both our WSGI application and the websocket
  handler within the same server
web: Significantly speed up download by pre-calculating the size without going through the whole iterator