Skip to content

Commit

Permalink
chore: calculate defaultUserAgent based on environment
Browse files Browse the repository at this point in the history
  • Loading branch information
mochaaP committed Feb 1, 2024
1 parent d4f358a commit 1a687df
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ const { webidl } = require('./webidl')
const { STATUS_CODES } = require('node:http')
const GET_OR_HEAD = ['GET', 'HEAD']

const isNode = typeof __UNDICI_IS_NODE__ !== 'undefined' || typeof esbuildDetection !== 'undefined'
const defaultUserAgent = typeof __UNDICI_IS_NODE__ !== 'undefined' || typeof esbuildDetection !== 'undefined'
? 'node'
: 'undici'

/** @type {import('buffer').resolveObjectURL} */
let resolveObjectURL
Expand Down Expand Up @@ -1474,7 +1476,7 @@ async function httpNetworkOrCacheFetch (
// user agents should append `User-Agent`/default `User-Agent` value to
// httpRequest’s header list.
if (!httpRequest.headersList.contains('user-agent', true)) {
httpRequest.headersList.append('user-agent', isNode ? 'node' : 'undici', true)
httpRequest.headersList.append('user-agent', defaultUserAgent)
}

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

0 comments on commit 1a687df

Please sign in to comment.