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

fix user-agent detection #2340

Closed
wants to merge 1 commit into from

Conversation

KhafraDev
Copy link
Member

refs: #2310 (comment)

I confirmed that this fixes the issue in node core.

@codecov-commenter
Copy link

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (e39a632) 85.54% compared to head (1ff7122) 92.28%.
Report is 42 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2340      +/-   ##
==========================================
+ Coverage   85.54%   92.28%   +6.73%     
==========================================
  Files          76       41      -35     
  Lines        6858     3253    -3605     
==========================================
- Hits         5867     3002    -2865     
+ Misses        991      251     -740     
Files Coverage Δ
lib/core/connect.js 80.00% <100.00%> (-1.25%) ⬇️
lib/core/request.js 88.09% <100.00%> (+1.01%) ⬆️
lib/pool.js 100.00% <100.00%> (ø)
lib/client.js 93.18% <92.30%> (+0.05%) ⬆️
lib/core/util.js 82.63% <85.71%> (-13.16%) ⬇️

... and 39 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@KhafraDev
Copy link
Member Author

esbuild will rename it to something else when rebundled, this doesn't work

@KhafraDev KhafraDev closed this Oct 11, 2023
httpRequest.headersList.append('user-agent', __filename.endsWith('index.js') ? 'undici' : 'node')
// __commonJS is injected by esbuild when bundled. The esbuild bundle is used in node core.
// Therefore if we're running the esbuild bundle, we're likely in node core.
httpRequest.headersList.append('user-agent', typeof __commonJS !== 'function' ? 'undici' : 'node')
Copy link
Collaborator

Choose a reason for hiding this comment

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

not a fan of relying on an unspecified global. Someone could decide to set this themselves and undici would break itself.

Copy link
Member Author

Choose a reason for hiding this comment

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

fwiw it's also possible to set __filename

Copy link
Collaborator

Choose a reason for hiding this comment

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

true but there is at least an assumption/definition for __filename. If someone decides to mess with that - it's on them.

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

3 participants