global: fixes for encoding and tests
- Changes handling legacy application request object write and flush methods in order to avoid sending headers to early.
- Cleanes legacy application main template to deal with 'utf-8' encoding problem.
- Multiple small fixes for making some of the regression tests run again.