Improve the finalization code of HTTPServerResponse.

The previous version was a bit brittle when code was changed.