Skip to content

Commit 1611ba6

Browse files
fix: Parse JSON contents from fetchLite() without gzip encoding
1 parent c193167 commit 1611ba6

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Utils.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,16 @@ describe("utils", () => {
155155
expect(fetchSuccess).toBeInstanceOf(Object)
156156
})
157157

158+
it("fetchLite: access to a private NPM Registry without auth token", async () => {
159+
expect.assertions(1)
160+
161+
const fetchSuccess = await fetchLite<{ error: string }>(
162+
"https://registry.npmjs.org/@fortawesome/pro-light-svg-icons"
163+
)
164+
165+
expect(fetchSuccess?.error).toBe("Not found")
166+
})
167+
158168
it("fetchLite: invalid URL", async () => {
159169
expect.assertions(1)
160170

src/Utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ export const fetchLite = <T>(
140140
// istanbul ignore next
141141
response.on("error", () => resolve(undefined))
142142
response.on("end", () => {
143+
if (!response.headers["content-encoding"]) {
144+
return resolve(JSON.parse(responseBuffers.toString()))
145+
}
146+
143147
return zlib.gunzip(
144148
Buffer.concat(responseBuffers),
145149
(_error, contents) => {

0 commit comments

Comments
 (0)