Refactoring about onBeforeSendHeaders