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

Migrate from Request #134

Closed
wants to merge 1 commit into from

Conversation

davidpatrick
Copy link
Contributor

Description

In response to the Request Deprecation request/request#3142 we have done our own assessment of the situation and potential replacements.

Requirements

We looked into our use of Request and found that we wanted to continue to support the current 5 features we use with request:

  • Handle JSON
  • Turn off strict ssl
  • Modifying headers
  • Modifying HTTP Agent Options
  • Specify Proxy

Additionally, we have had requests for further use of the request library. Because of this, we want to expose the config of the under pinning http library we choose.

Research

We looked into using the following

  • internal http/https lib
  • node-fetch
  • axios
  • got

Axios is the only library that supports all 5 features out of the box. Got and node-fetch met all requirements, however required workaround or external library for using a proxy. After testing each option, Axios required the least amount of configuration on this libraries end.

Migration

To expose the under pinning library we use to make requests, we will be changing the API for controlling the http agent, headers, proxy, and exposing a new option httpOptions that will passthrough to Axios https://github.com/axios/axios/tree/v0.19.2#request-config

Fixes issue #126

@davidpatrick davidpatrick added this to the v2-Next milestone Mar 18, 2020
@davidpatrick davidpatrick requested a review from a team March 18, 2020 22:59
@adamjmcgrath adamjmcgrath requested review from adamjmcgrath and removed request for adamjmcgrath March 19, 2020 09:59
@adamjmcgrath adamjmcgrath self-assigned this Mar 19, 2020
...this.options.httpOptions
})
.then(res => {
if (res.statusCode < 200 || res.statusCode >= 300) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default axios rejects non 2xx status codes, using the validateStatus option. So this code path will never be hit (unless the user overriders validateStatus)

if (res) {
return cb(new JwksError(res.body && (res.body.message || res.body) || res.statusMessage || `Http Error ${res.statusCode}`));

return axios.request({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would favour removing the return statement, just because it might confuse


const client = new JwksClient({
jwksUri: `${jwksHost}/.well-known/jwks.json`
});

client.getKeys(err => {
expect(err).not.to.be.null;
expect(err.message).to.equal('Unknown Server Error');
expect(err.message).to.equal('Request failed with status code 500');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could add an assertion that error is of type JwksError

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the JwksError expectation, correctly exposes this issue #134 (comment)

@davidpatrick davidpatrick changed the title Migrate from Request to Axios Migrate from Request Mar 31, 2020
@davidpatrick
Copy link
Contributor Author

Closing this PR in favor of opening a new one where we will replace request library without any breaking changes.

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

Successfully merging this pull request may close these issues.

2 participants