simplify onBeforeSendHeadersHandler using helpers