1) Register for RQ_SEND_RESPONSE, check the status code, and in case of 401 response, add your custom headers using IHttpResponse::SetHeader
2) There is no direct equivalent, it would be a combination of whether you want to send an error response to the client (IHttpResponse::SetStatus) and/or whether you want to short-circuit the state machine (RQ_NOTIFICATION_FINISH_REQUEST)