This is a new version of b6b16fec2a60 (which was backed out in faf83e1e40f5),
with an extra line removed to fix problems with hg serve. hg's internal web
server contains checking if the app isn't trying to write more bytes than
specified by the Content-Length header. The first try still contained an old
line that wrote the response, so the response was sent twice.
This removes the ability for templates to add custom HTTP headers, which can
easily be re-added if someone needs it. Thanks to asak for repeatedly reviewing
this patch and helping to iron out the quirks.