http-client
http-client copied to clipboard
response.body is Gunzip?!
I'm trying something quite simple:
let fetch = httpClient.createFetch(
httpClient.base("https://steemit.com"),
httpClient.accept('application/json'),
httpClient.parse('json'),
httpClient.debug()
);
fetch(`/@iontichy.json`)
.then((response) => {
console.log(response.json)
})
.catch(console.error)
The result left me speechless. I expected response.json
to be there. It was not. I checked the response for response.body
and this is what I found:
Gunzip {_readableState: ,readable: true,domain: ,_events: ,_eventsCount: 7,...}
This is clearly a bug, yes? How do I get my data out of this Gunzip thing?!
Addendum: when giving {compress: false} as options for the fetch, it will return a PassThrough
object. Using it however it pointless, on attempting to pipe it into a writeable stream, it throws an exception:
Error [ERR_METHOD_NOT_IMPLEMENTED]: The _transform method is not implemented
Something is seriously messed up here. By the way: i'm using node 9.
Try this:
let fetch = httpClient.createFetch(
httpClient.base("https://steemit.com"),
httpClient.accept('application/json'),
httpClient.parse('json')
);
fetch(`/@iontichy.json`)
.then((response) => {
let json = "";
response.on('data', (data) => json += data.toString());
response.on('end', () => console.log(JSON.parse(json)));
})
.catch(console.error)