[HttpFoundation] factorize out the way output buffers should be closed