http-client icon indicating copy to clipboard operation
http-client copied to clipboard

response.body is Gunzip?!

Open JuergenSimon opened this issue 7 years ago • 2 comments

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?!

JuergenSimon avatar Feb 13 '18 17:02 JuergenSimon

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.

JuergenSimon avatar Feb 13 '18 18:02 JuergenSimon

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)

bra1n avatar Mar 09 '18 12:03 bra1n