Expose Flush Cookie API based on #313

Cherry pick commit from  Exposing flushcookie api. #313, manually fix merge issues and rename interface to make a little more consistent.