Code Monkey home page Code Monkey logo

node-request-light's Introduction

request-light

npm Package NPM Downloads Build Status License: MIT

A lightweight request library intended to be used by VSCode extensions.

  • NodeJS and browser main entry points
  • proxy support: Use configure or HTTP_PROXY and HTTPS_PROXY env variables to configure the HTTP proxy addresses.
import { xhr, XHRResponse, getErrorStatusDescription } from 'request-light';

const headers = { 'Accept-Encoding': 'gzip, deflate' };
return xhr({ url: url, followRedirects: 5, headers }).then(response => {
    return response.responseText;
}, (error: XHRResponse) => {
    throw new Error(error.responseText || getErrorStatusDescription(error.status) || error.toString());
});

node-request-light's People

Contributors

aeschli avatar dependabot[bot] avatar estebandalelr avatar evidolob avatar lramos15 avatar lszomoru avatar microsoft-github-policy-service[bot] avatar msftgits avatar msivasubramaniaan avatar rzhao271 avatar tarrowren avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-request-light's Issues

Response stream need error handling

need readable.on('error', ...), otherwise current process will cash when gzip is used and response data is corrupted

let headers = { 'Accept-Encoding': 'gzip, deflate' };
let request = require('request-light');

setInterval(() => {
  console.log('process running..');
}, 2000);

request.xhr({ url: 'http://json.schemastore.org/tsconfig', followRedirects: 5, headers: headers })
  .then(res => {
    console.log('res', res);
  })
  .catch(err => {
    console.error('err');
  });
node xhr-test.js 
events.js:193
      throw er; // Unhandled 'error' event
      ^

Error: incorrect data check
    at Zlib.zlibOnError [as onerror] (zlib.js:133:17)

Add documentation to README

This extension is recommended by an extension authoring docs page, so I'm assuming it's ready for production use. However there's no docs anywhere, I couldn't even find what to import from the package.

HTTP errors on Windows

After I started using request-light instead of the http module to query Chrome for its debug targets, several users on Windows reported getting HTTP errors in this issue https://github.com/Microsoft/vscode-chrome-debug/issues/237. They reported getting 504, 403, and 401 where previously it had been working for them, and they could open the url in a browser.

In this case my code looks like this: https://github.com/Microsoft/vscode-chrome-debug-core/blob/v2.0.2/src/utils.ts#L222 which is basically copied from where vscode-node-debug uses it to download sourcemaps. Below on line 240 is the original code, and when I switched back to that, it worked again. It's very simple, the url was something like http://127.0.0.1:9222/json. I was never able to repro it. Looking at what request-light does, it looks like it should behave the same as the basic http.get. Any idea why this would happen?

Cancellation support?

Hi, can cancellation support be added, either with AbortController or even better, with vs code style cancellation tokens?

Does this work with `NODE_EXTRA_CA_CERTS`?

We have some pretty awesome security software that does this man-in-the-middle-attack TLS interception where it decrypts and re-encrypts all TLS traffic.

For Node apps, I've been able to add the environment variable NODE_EXTRA_CA_CERTS and point it to the security software certificate.

It doesn't seem that this obeys that construct, or perhaps the environment in VS Code extensions isn't seeing that value propagated down? I'm encountering issues while trying to use the Azure Pipelines Language Server that uses this library. It pretty consistently issues a message like: "Error: Unable to get local issuer certificate" and that generally points at this MitM thing.

Add documentation to README

I work on several Azure extensions for VS Code (For example https://github.com/Microsoft/vscode-azurefunctions). We're trying to work with proxies and I found this package. The README is a little lacking haha so I had a few questions:

  1. Is this package ready for use and in a reliable state?
  2. Can most extensions ignore configure? It seems like getSystemProxyURI would configure for us
  3. Any chance you could export getProxyAgent? Most of the time we go through an Azure ServiceClient instead of making the request directly. Even though we're not making the request, we can still pass in requestOptions to the constructor, which is where getting just the agent would come in handy.

NO_PROXY support

Overview

The library takes provided proxy url or use system configured proxy in environment variable. However, proxies don't work for internal resources and sending request to e.g. localhost or other internal corporate resources fails, depending on proxy configuration.

To do

Provide a way to get binary data

It seems that the response is always given as data.join('') in node, but when dealing with binary data, the original data Buffers are needed (to then write them to a stream created by fs.createWriteStream).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.