2
0
mirror of https://github.com/tenrok/axios.git synced 2026-05-15 11:59:42 +03:00

fix(http): add zlib headers if missing (#5497)

This commit is contained in:
ItsNotGoodName
2023-01-30 14:49:37 -08:00
committed by GitHub
parent 9915635c69
commit 65e8d1e28c
3 changed files with 43 additions and 2 deletions
+28
View File
@@ -0,0 +1,28 @@
"use strict";
import stream from "stream";
class ZlibHeaderTransformStream extends stream.Transform {
__transform(chunk, encoding, callback) {
this.push(chunk);
callback();
}
_transform(chunk, encoding, callback) {
if (chunk.length !== 0) {
this._transform = this.__transform;
// Add Default Compression headers if no zlib headers are present
if (chunk[0] !== 120) { // Hex: 78
const header = Buffer.alloc(2);
header[0] = 120; // Hex: 78
header[1] = 156; // Hex: 9C
this.push(header, encoding);
}
}
this.__transform(chunk, encoding, callback);
}
}
export default ZlibHeaderTransformStream;