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

feat: Query string params #1449

Merged
merged 37 commits into from May 19, 2022
Merged

feat: Query string params #1449

merged 37 commits into from May 19, 2022

Conversation

kibertoad
Copy link
Contributor

fixes #1448

ronag and others added 6 commits March 22, 2021 11:27
…8-params

� Conflicts:
�	README.md
�	index.js
�	lib/core/client.js
�	test/client-stream.js
�	test/client.js
�	test/headers-as-array.js
�	test/socket-handle-error.js
�	types/client.d.ts
test/client.js Outdated Show resolved Hide resolved
lib/core/request.js Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented May 18, 2022

Codecov Report

Merging #1449 (79610dd) into main (3b5353a) will increase coverage by 0.05%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1449      +/-   ##
==========================================
+ Coverage   94.37%   94.42%   +0.05%     
==========================================
  Files          49       49              
  Lines        4231     4272      +41     
==========================================
+ Hits         3993     4034      +41     
  Misses        238      238              
Impacted Files Coverage Δ
lib/core/request.js 98.65% <100.00%> (ø)
lib/core/util.js 98.68% <100.00%> (+0.19%) ⬆️
lib/fetch/response.js 88.95% <0.00%> (+1.11%) ⬆️
lib/fetch/util.js 81.25% <0.00%> (+1.25%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3b5353a...79610dd. Read the comment docs.

@ronag
Copy link
Member

ronag commented May 18, 2022

Also needs docs.

@kibertoad
Copy link
Contributor Author

@ronag Documentation added, sorry. Slipped through the cracks while I was resolving conflicts with main, documentation was heavily restructured since then.

@kibertoad
Copy link
Contributor Author

Failed test seems to be flaky.

@kibertoad kibertoad closed this May 18, 2022
@kibertoad kibertoad reopened this May 18, 2022
@kibertoad kibertoad closed this May 18, 2022
@kibertoad kibertoad reopened this May 18, 2022
@kibertoad
Copy link
Contributor Author

OK, there seems to be very specific error happening on Node 16 on Windows. Super fun. Will investigate.

lib/core/request.js Outdated Show resolved Hide resolved
lib/core/request.js Outdated Show resolved Hide resolved
@kibertoad
Copy link
Contributor Author

@ronag This is ready for rereview. Please let me know if you want additional tests for any cases.

lib/core/request.js Outdated Show resolved Hide resolved
kibertoad and others added 2 commits May 19, 2022 14:23
Co-authored-by: Robert Nagy <ronagy@icloud.com>
lib/core/util.js Outdated

// this escapes all non-uri friendly characters, but restores : which is commonly used for date formatting
function encode (val) {
return encodeURIComponent(val).replace(/%3A/gi, ':')
Copy link
Member

Choose a reason for hiding this comment

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

Why restore :? I don't understand the use case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Escaping : is going to mess up date format and complicate rather frequent use-case.
I'm having second thoughts about escaping anything, TBH, especially since Undici is not supposed to be used from browser. What do you think about removing escaping completely and let user do it if they need to?

Copy link
Member

@ronag ronag May 19, 2022

Choose a reason for hiding this comment

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

What does got do?

Copy link
Member

Choose a reason for hiding this comment

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

I think we actually need to escape or we might end up with invalid URLs, e.g. if they contain ?, & etc...

Copy link
Member

Choose a reason for hiding this comment

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

I think encodeURIComponent is sufficient for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got is using URLSearchParams, and there are already issues with that: sindresorhus/got#1180
If we go with escaping, I would suggest following axios example instead of got - they were around for much longer, and had all the time in the world to work out the kinks of real world usage.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I understand the use case. Is it that some server implementations don't decode query parameters at all?

Copy link
Member

@ronag ronag May 19, 2022

Choose a reason for hiding this comment

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

I'd prefer if we just keep it simple and use encodeURIComponent. Anything else feels opinionated to me.

Copy link
Member

Choose a reason for hiding this comment

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

I agree

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

lib/core/util.js Outdated Show resolved Hide resolved
lib/core/util.js Outdated
if (serializedParams) {
const hashmarkIndex = url.indexOf('#')
if (hashmarkIndex !== -1) {
url = url.slice(0, hashmarkIndex)
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit magical...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can drop it, if you like

Copy link
Member

Choose a reason for hiding this comment

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

Throw if #?

Copy link
Member

Choose a reason for hiding this comment

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

This is not resolved yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry, change was done and test was added, but some garbage left behind

lib/core/util.js Outdated Show resolved Hide resolved
lib/core/util.js Outdated Show resolved Hide resolved
kibertoad and others added 4 commits May 19, 2022 14:29
Co-authored-by: Robert Nagy <ronagy@icloud.com>
Co-authored-by: Robert Nagy <ronagy@icloud.com>
lib/core/util.js Outdated

for (const v of val) {
if (isDate(v)) {
throw new Error('Passing date as a query param is not supported, please serialize to string up-front')
Copy link
Member

Choose a reason for hiding this comment

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

Date is an object so the check below is sufficient.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@ronag
Copy link
Member

ronag commented May 19, 2022

Thanks

@ronag ronag merged commit 15d5875 into nodejs:main May 19, 2022
@kibertoad
Copy link
Contributor Author

Thank you so much! 🎉

@kibertoad kibertoad deleted the feat/1448-params branch May 19, 2022 16:08
KhafraDev pushed a commit to KhafraDev/undici that referenced this pull request Jun 23, 2022
metcoder95 pushed a commit to metcoder95/undici that referenced this pull request Dec 26, 2022
crysmags pushed a commit to crysmags/undici that referenced this pull request Feb 27, 2024
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.

Support for query params
5 participants