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

Normalize the URL in the baseUrl option #579

Merged
merged 8 commits into from Aug 23, 2018

Conversation

szmarczak
Copy link
Collaborator

@szmarczak szmarczak commented Aug 23, 2018

Fixes #562

const instanceA = got.extend({baseUrl: `${s.url}/test/`});
const {body} = await instanceA('/foobar');
t.is(body, `/test/foobar`);
});
Copy link
Owner

Choose a reason for hiding this comment

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

Can you also add a test with await instanceA('foobar');?

Copy link
Owner

Choose a reason for hiding this comment

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

And a couple of tests where the baseUrl is a WHATWG URL object.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yup

return options;
};

module.exports.prenormalize = prenormalize;
Copy link
Owner

Choose a reason for hiding this comment

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

prenormalize is not a word, so should be preNormalize

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure

@sindresorhus
Copy link
Owner

The docs needs to be updated too.

@sindresorhus
Copy link
Owner

Rewrite the baseUrl option

Would be more descriptive to title the PR:

Normalize the URL in the baseUrl option

@sindresorhus
Copy link
Owner

Can you comment on why it was necessary to split it out into a preNormalize step?

@szmarczak
Copy link
Collaborator Author

Can you comment on why it was necessary to split it out into a preNormalize step?

Code comment or GitHub comment?

@sindresorhus
Copy link
Owner

Just a comment on this thread is fine.

@@ -13,6 +13,47 @@ const knownHookEvents = require('./known-hook-events');

const retryAfterStatusCodes = new Set([413, 429, 503]);

const preNormalize = options => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've split normalize-argument.js into two parts:

  • preNormalize handles all the stuff which is related with static options like baseUrl, followRedirect, hooks etc.
    It is used in got.create() to normalize defaults.options.
  • normalize does preNormalize + handles all the stuff related with dynamic options like url, headers, body etc.

@sindresorhus sindresorhus changed the title Rewrite the baseUrl option Normalize the URL in the baseUrl option Aug 23, 2018
@sindresorhus sindresorhus merged commit c901c46 into sindresorhus:master Aug 23, 2018
@sindresorhus
Copy link
Owner

Looking great!

68747470733a2f2f6d656469612e67697068792e636f6d2f6d656469612f6c3045786b3845557a534c7372457245512f67697068792e676966

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.

None yet

2 participants