refactor and support both native and http