diff --git a/packages/web/src.ts/geturl.ts b/packages/web/src.ts/geturl.ts index d2ed519d98..2dfaba229f 100644 --- a/packages/web/src.ts/geturl.ts +++ b/packages/web/src.ts/geturl.ts @@ -2,9 +2,11 @@ import http from "http"; import https from "https"; +import { gunzipSync } from "zlib"; import { parse } from "url" -import { concat } from "@ethersproject/bytes"; +import { arrayify, concat } from "@ethersproject/bytes"; +import { shallowCopy } from "@ethersproject/properties"; import type { GetUrlResponse, Options } from "./types"; @@ -38,6 +40,11 @@ function getResponse(request: http.ClientRequest): Promise { }); resp.on("end", () => { + if (response.headers["content-encoding"] === "gzip") { + //const size = response.body.length; + response.body = arrayify(gunzipSync(response.body)); + //console.log("Delta:", response.body.length - size, Buffer.from(response.body).toString()); + } resolve(response); }); @@ -73,9 +80,13 @@ export async function getUrl(href: string, options?: Options): Promise { return new Promise((resolve) => { @@ -43,6 +43,7 @@ export type ConnectionInfo = { password?: string, allowInsecureAuthentication?: boolean, + allowGzip?: boolean, throttleLimit?: number, throttleSlotInterval?: number; @@ -100,7 +101,7 @@ export function _fetchData(connection: string | ConnectionInfo, let url: string = null; // @TODO: Allow ConnectionInfo to override some of these values - const options: any = { + const options: Options = { method: "GET", }; @@ -131,6 +132,8 @@ export function _fetchData(connection: string | ConnectionInfo, } } + options.allowGzip = !!connection.allowGzip; + if (connection.user != null && connection.password != null) { if (url.substring(0, 6) !== "https:" && connection.allowInsecureAuthentication !== true) { logger.throwError( diff --git a/packages/web/src.ts/types.ts b/packages/web/src.ts/types.ts index 8ab7bfb7a1..1596e2f0df 100644 --- a/packages/web/src.ts/types.ts +++ b/packages/web/src.ts/types.ts @@ -9,6 +9,7 @@ export type GetUrlResponse = { export type Options = { method?: string, + allowGzip?: boolean; body?: Uint8Array headers?: { [ key: string] : string }, };