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
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,9 @@ async function httpNetworkOrCacheFetch (
// user agents should append `User-Agent`/default `User-Agent` value to
// httpRequest’s header list.
if (!httpRequest.headersList.contains('user-agent')) {
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.

}

// 15. If httpRequest’s cache mode is "default" and httpRequest’s header
Expand Down
Loading