diff --git a/src/http/gateway/resources/gateway.js b/src/http/gateway/resources/gateway.js index cc3728d113..ccdc8aa68b 100644 --- a/src/http/gateway/resources/gateway.js +++ b/src/http/gateway/resources/gateway.js @@ -6,7 +6,6 @@ log.error = debug('ipfs:http-gateway:error') const fileType = require('file-type') const mime = require('mime-types') -const { PassThrough } = require('readable-stream') const Boom = require('@hapi/boom') const Ammo = require('@hapi/ammo') // HTTP Range processing utilities const peek = require('buffer-peek-stream') @@ -32,20 +31,6 @@ function detectContentType (path, chunk) { return mime.contentType(mimeType) } -// Enable streaming of compressed payload -// https://github.com/hapijs/hapi/issues/3599 -class ResponseStream extends PassThrough { - _read (size) { - super._read(size) - if (this._compressor) { - this._compressor.flush() - } - } - setCompressor (compressor) { - this._compressor = compressor - } -} - module.exports = { async handler (request, h) { @@ -149,7 +134,6 @@ module.exports = { } const rawStream = ipfs.catReadableStream(data.cid, catOptions) - const responseStream = new ResponseStream() // Pass-through Content-Type sniffing over initial bytes const { peekedStream, contentType } = await new Promise((resolve, reject) => { @@ -163,9 +147,7 @@ module.exports = { }) }) - peekedStream.pipe(responseStream) - - const res = h.response(responseStream).code(rangeResponse ? 206 : 200) + const res = h.response(peekedStream).code(rangeResponse ? 206 : 200) // Etag maps directly to an identifier for a specific version of a resource // and enables smart client-side caching thanks to If-None-Match diff --git a/src/http/index.js b/src/http/index.js index 38a9982e67..205c9edc16 100644 --- a/src/http/index.js +++ b/src/http/index.js @@ -82,7 +82,11 @@ class HttpApi { // TODO: shouldn't, fix this routes: { cors: true - } + }, + // Disable Compression + // Why? Streaming compression in Hapi is not stable enough, + // it requires bug-prone hacks such as https://github.com/hapijs/hapi/issues/3599 + compression: false }) server.app.ipfs = ipfs