在尝试http.get
gzip压缩json文件时,Ionic 3 / Angular中的.get
出现问题。
当我在localhost上测试时,我正在获取gzip压缩内容,但是当我将应用程序部署到Web时,响应已经解压缩。
这可以通过检查result.byteLength
来看到,它在localhost上返回打包文件的长度,并在Web上返回解压缩文件的长度。 (另外,在检查返回的ArrayBuffer时,很明显在一种情况下,内容被gzip压缩,而在其他情况下,结果已经解压缩。)
那么 - 有没有办法以一种不依赖于资产托管位置的方式.get
gzip压缩文件?
我更愿意总是获得解压缩的json内容,但我不介意自己夸大响应(我正在使用pako库),但我需要知道响应是否已经解压缩。
import { HttpClient } from '@angular/common/http';
...
this.http.get("./assets/dict.json.gz", { responseType: 'arraybuffer' } ).subscribe(
(result) => {
console.log(result.byteLength); // <<<!!! not same when getting response from localhost and from server!
// do something with response...
},
(err) => {
console.error("Dictionary load failure: ");
console.log(err);
},
() => {
// console.log("loadDict done");
});