Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd a gunzipping option #192
Conversation
@@ -9,6 +9,7 @@ const Https = require('https'); | |||
const Stream = require('stream'); | |||
const Hoek = require('hoek'); | |||
const Boom = require('boom'); | |||
const Zlib = require('zlib'); |
This comment has been minimized.
This comment has been minimized.
@@ -356,25 +360,54 @@ internals.Client.prototype.read = function (res, options, callback) { | |||
return callback(null, null); | |||
} | |||
|
|||
if (options.json === 'force') { | |||
const parse = () => { |
This comment has been minimized.
This comment has been minimized.
geek
Aug 30, 2017
Member
feel free to delete the // Parse JSON
comment above this.. maybe rename the parse function to parseJSON ?
@@ -11,6 +11,7 @@ const Stream = require('stream'); | |||
const Hoek = require('hoek'); | |||
const Lab = require('lab'); | |||
const Reload = require('require-reload'); | |||
const Zlib = require('zlib'); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@Marsup For the build issues, maybe make the test more relaxed on the error message:
change to
change to
either that or have custom node version checks in the test :/ |
The gunzipping means that any Either these need be corrected somehow, or at least documented that they have been invalidated. I suspect it will have to be the latter. |
const contentType = (res.headers && internals.findHeader('content-type', res.headers)) || ''; | ||
const mime = contentType.split(';')[0].trim().toLowerCase(); | ||
if (contentEncoding === 'gzip') { | ||
Zlib.gunzip(buffer, (err, gunzipped) => { |
This comment has been minimized.
This comment has been minimized.
kanongil
Aug 31, 2017
Member
I would much prefer to use streaming gunzip, rather than the sync one that you use. Eg. create a passthrough gunzip stream and pipe through it. This might even be a simpler implementation.
This comment has been minimized.
This comment has been minimized.
I don't think |
This comment has been minimized.
This comment has been minimized.
It seems I was too quick regarding Regarding fixes, I suspect nothing much can be done, since the headers are part of the native |
if (options.gunzip) { | ||
const contentEncoding = options.gunzip === 'force' ? | ||
'gzip' : | ||
(res.headers && internals.findHeader('content-encoding', res.headers)) || ''; |
This comment has been minimized.
This comment has been minimized.
kanongil
Aug 31, 2017
Member
This doesn't handle multiple encoding entries. Eg. gzip, identity
can be supported.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Looking at it, I'm not sure this feature is compatible with the hands off approach of wreck. We really need more control of the exposed output to handle this transparently. Maybe it can work if it is only enabled for the helper methods, where we have tighter control of the output. |
This comment has been minimized.
This comment has been minimized.
So you'd rather not have it in wreck ? I'll let Wyatt decide on this, but I think it's a pretty common thing to do, and it's an opt-in feature so I'm not forcing it on anyone. Updated to stream mode as suggested and doc changes. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
A couple more issues: If the server provides a Secondly, old servers can signal |
This comment has been minimized.
This comment has been minimized.
I also don't like that there is not way to know whether the buffer has been transparently gunzipped, or not. |
This comment has been minimized.
This comment has been minimized.
OK, then I'll ask for an option to completely disable JSON parsing, because right now the auto-detection is killing any attempt I do at handling the gzipping externally. |
This comment has been minimized.
This comment has been minimized.
A completely different issues, is that I would expect this feature to somehow add a |
This comment has been minimized.
This comment has been minimized.
Enabling the feature and checking the
This is a good point. Since this is an opt-in feature that is brand new, I don't think we need to address this particular use case yet. If someone is in need of this support we can address it then. |
Marsup commentedAug 30, 2017
As discussed with you, here's a gunzip option. I think it's my 1st significant contribution to wreck so be careful ;)