Skip to content
This repository has been archived by the owner on Jul 30, 2018. It is now read-only.

core/request : node provider does not decompress #259

Closed
sebilasse opened this issue Dec 29, 2016 · 3 comments
Closed

core/request : node provider does not decompress #259

sebilasse opened this issue Dec 29, 2016 · 3 comments
Assignees
Milestone

Comments

@sebilasse
Copy link

sebilasse commented Dec 29, 2016

It should handle gzip and deflate, e.g.
https://github.com/dojo/core/blob/master/src/request/node.ts

import * as zlib from 'zlib';

for line 319 - 326

const contentEncoding = nativeResponse.headers['content-encoding'];
if (contentEncoding === 'gzip' || contentEncoding === 'deflate') {
    // If compressed, decompress
    const cMethod = (contentEncoding === 'gzip') ? 'gunzip' : 'inflate';
    zlib[cMethod](response.data, function(err: Error, decodedResponse: any) {
        if (err) { reject(err); }
        response.data = decodedResponse;
        resolve(response);
    });
} else if (!options.streamTarget) {
    // If using a streamTarget, wait for it to finish in case it throws an error
    resolve(response);
} else {
    options.streamTarget.close();
}

But please note that
const contentEncoding = nativeResponse.headers['content-encoding'];
is guaranteed to work only w. node/express because HTTP header fields are usually case-insensitive ...

@sebilasse sebilasse changed the title request : node provider does not decompress core/request : node provider does not decompress Jan 2, 2017
@sebilasse
Copy link
Author

sebilasse commented Jan 16, 2017

Another suggestion for the node provider is to add a message to the cryptic E-messages.
Could be like

const ErrorMessages = [
  'FileNotFoundError: The file was not found where specified ...',
  'FileAccessError: During a file-access or disk-access operation we could not '+
    'make a connection between the path and the file name.',
  'EOFError: Either we could not parse the End of File (e.g a forgotten ending '+
    'curly brace for a block of code) or there was no data.',
  'UnknownHostError: The destination computer (host server name) cannot be resolved.',
  'SocketError: A socket-related error occured.',
  'ProtocolError: The received answer of the server was complete but there was a '+
    'protocol error, e.g. CA certs and node: https://github.com/nodejs/node/issues/2244',
  'FileSystemError: Please repair your FileSystem.',
  'ConnectError: There is an error with the connection. Usually an error of the host server.',
  'BindError: When the allowed connections are exhausted, you get this error when trying '+
    'to make any new connections.',
  'AddressNotFoundError: This address could not be found.',
  'NetworkError: You were somehow offline when accessing the URL.'
];

const Errors = {
  ENOENT: 0,
  EACCES: 1, EPERM: 1,
  EOF: 2,
  EADDRINFO: 3,
  EISCONN: 4, ENOTCONN: 4, ENOTSOCK: 4, ENOTSUP: 4, EAIFAMNOSUPPORT: 4, EAISERVICE: 4,
  EPROTO: 5, EPROTONOSUPPORT: 5, EPROTOTYPE: 5,
  EBUSY: 6, EAGAIN: 6, EBADF: 6, EMFILE: 6, ENOTDIR: 6, EISDIR: 6, EEXIST: 6, ENAMETOOLONG: 6, ELOOP: 6,
  ENOTEMPTY: 6, ENOSPC: 6, EIO: 6, EROFS: 6, ENODEV: 6, ESPIPE: 6, ECANCELED: 6, ENFILE: 6, EXDEV: 6,
  ECONNABORTED: 7, ECONNREFUSED: 7, ECONNRESET: 7, ETIMEDOUT: 7,
  EADDRNOTAVAIL: 8,
  ENOTFOUND: 9,
  EAFNOSUPPORT: 10, EALREADY: 10,  EDESTADDRREQ: 10, EHOSTUNREACH: 10, EMSGSIZE: 10,
  ENETDOWN: 10, ENETUNREACH: 10, ENONET: 10, EPIPE: 10, EAISOCKTYPE: 10, ESHUTDOWN: 10
}

The value of Errors means the index of ErrorMessages : ErrorMessages[Errors[myNodeError]]

@dylans dylans added this to the 2017.02 milestone Jan 27, 2017
@rorticus rorticus self-assigned this Feb 6, 2017
rorticus added a commit to rorticus/core that referenced this issue Feb 6, 2017
@rorticus
Copy link
Contributor

rorticus commented Feb 6, 2017

gzip/deflate support added in #261

rorticus added a commit to rorticus/core that referenced this issue Feb 9, 2017
rorticus added a commit that referenced this issue Feb 10, 2017
* Updating request library to mimic fetch API, removing dependency on streams

* Exporting correct interface file now

* Request respones now using a queing event model

* Removing arraybuffer/blob tests if the environment doesnt support them

* Removing arrayBuffer test if blob isnt supported

* Adding OPTIONS, HEAD convienence methods

* Fixing import

* Allowing for relative redirects in node provider, issue #278

* Rebasing onto latest

* Handling gzip/deflate compression in node provider issue #259

* Rebasing on latest

* Review feedback

* Moving XHR responseType back
@rorticus
Copy link
Contributor

Fixed in #261

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants