fix the cannot set headers after they are sent.