Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plan to remove request lib #11095

Open
wewindy opened this issue Feb 21, 2023 · 3 comments
Open

Plan to remove request lib #11095

wewindy opened this issue Feb 21, 2023 · 3 comments

Comments

@wewindy
Copy link
Contributor

wewindy commented Feb 21, 2023

Hi, I am planning to remove the old dependency request, since it is deprecated for 2 years, and I prefer to use node-fetch to instead of it.

Here was an discussion about what libs can alternative with request: Alternative libraries to request #3143

There are two things confused me:

  • What type and value may proxy param is? Is it a URL string?
  • How to handle error
// server.js
request.get(
  {
    url: remoteUrl.toString(),
    headers: filterHeaders(req, req.headers),
    encoding: null,
    proxy: proxy,
  },
  //eslint-disable-next-line no-unused-vars
  function (error, response, body) {
    let code = 500;

    if (response) {
      code = response.statusCode;
      res.header(filterHeaders(req, response.headers));
    }

    res.status(code).send(body);
  }
);

Will be:

import fetch from "node-fetch";

// ...

let statusCode = 500;
fetch(remoteUrl.toString(), {
  headers: filterHeaders(req, req.headers),
  agent: proxy // I do not know whether correct or not to set proxy here
}).then((responseStream) => {
  statusCode = responseStream.status;
  res.header(filterHeaders(req, responseStream.headers));
  return responseStream.arrayBuffer(); // use `arrayBuffer()` to pipe responseBody in raw bytes format
}).then((responseBody) => {
  res.status(statusCode).send(responseBody);
}).catch((err) => {
  // How to handle error?
})

Thanks!

@wewindy
Copy link
Contributor Author

wewindy commented Feb 21, 2023

For code preview: server.js#L474

@ggetz
Copy link
Contributor

ggetz commented Feb 21, 2023

Hi @onsummer! We agree node-fetch would be the best replacement here, which was used as a replacement for request in gulpfile.js.

@ggetz
Copy link
Contributor

ggetz commented Jan 10, 2025

We removed "request" from all of our tooling, but not the package.json for some reason. Should be a simple cleanup.

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

No branches or pull requests

2 participants