Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

fix(gateway): disable compression #2245

Merged
merged 1 commit into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions src/http/gateway/resources/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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) {
Expand Down Expand Up @@ -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) => {
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down