downloadform - revamp of the webapp

- Using a connection pool instead of reopenning raw connection to postgresql database (which leads to issue #657)
- Adding a unit test (from 0% to 94% code covered by the testsuite)
- Fixing some potential bugs revealed by the tests

Also tested at runtime. I would like @jesseeichar to review it ;-)