HomePhabricator

Set custom User-Agent header on requests

Description

Set custom User-Agent header on requests

The Wikimedia Foundation's Varnish setup blocks requests with the
default 'node-fetch' User-Agent string[1], which we can avoid by setting
a more descriptive and specific custom User-Agent string.

Do this by implementing a simple wrapper on top of node-fetch that sets
the desired User-Agent header, as suggested in [2]. The wrapper is also
a logical place in which to patch in Bluebird as the Promise library,
rather than doing it every time we import fetch.

To ensure all usage of node-fetch is proxied through the wrapper, add an
eslint node/no-restricted-require check for the module.

[1]: https://github.com/wikimedia/puppet/blob/9843300dba/modules/varnish/templates/wikimedia-frontend.vcl.erb#L716-L718
[2]: https://github.com/node-fetch/node-fetch/issues/591#issuecomment-474457866

Bug: T316886
Change-Id: I9d7bd466bc16a55e53414ba3f8b92a3c66f53ca1

Details

Provenance
oriAuthored on Sep 1 2022, 7:51 PM
Parents
rMSFO9b4191415adc: Merge "Centralize access to a shared logger object"
Branches
Unknown
Tags
Unknown
References
refs/changes/60/829060/2
ChangeId
I9d7bd466bc16a55e53414ba3f8b92a3c66f53ca1