Skip to content

Commit

Permalink
fix: support global "_Headers" in Undici 5.26.3 (#73)
Browse files Browse the repository at this point in the history
Node.js's update to Undici 5.26.3 caused its `Headers` class to be
called `_Headers`:


https://github.com/nodejs/node/pull/50153/files#diff-f516ab824a7722da938a4c7c851520d39731ddeb4f7198dff4e932c5d4f8fdf7

Fixes #72.

---------

Co-authored-by: Artem Zakharchenko <kettanaito@gmail.com>
  • Loading branch information
joshkel and kettanaito authored Oct 18, 2023
1 parent cab2ae2 commit 49a4386
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 21 deletions.
23 changes: 5 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ on:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16, 18]
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -21,27 +23,12 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 16
node-version: ${{ matrix.node-version }}
always-auth: true
cache: yarn

- name: Setup Git
run: |
git config --local user.name "kettanaito"
git config --local user.email "kettanaito@gmail.com"
- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Unit tests
run: yarn test

- name: Build
run: yarn build

- name: Release
if: contains(github.ref, 'refs/heads/main')
run: yarn release
env:
GITHUB_TOKEN: ${{ secrets.GH_ADMIN_TOKEN }}
NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
42 changes: 42 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: release

on:
push:
branches:
- main
workflow_dispatch:

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
token: ${{ secrets.GH_ADMIN_TOKEN }}

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
always-auth: true
cache: yarn

- name: Setup Git
run: |
git config --local user.name "kettanaito"
git config --local user.email "kettanaito@gmail.com"
- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Build
run: yarn build

- name: Release
if: contains(github.ref, 'refs/heads/main')
run: yarn release
env:
GITHUB_TOKEN: ${{ secrets.GH_ADMIN_TOKEN }}
NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
7 changes: 4 additions & 3 deletions src/Headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ export class Headers {

constructor(init?: HeadersInit | HeadersObject | HeadersList) {
/**
* @note Cannot check if the `init` is an instance of the `Headers`
* because that class is only defined in the browser.
* @note Cannot necessarily check if the `init` is an instance of the
* `Headers` because that class may not be defined in Node or jsdom.
*/
if (
['Headers', 'HeadersPolyfill'].includes(init?.constructor.name) ||
init instanceof Headers
init instanceof Headers ||
(typeof globalThis.Headers !== 'undefined' && init instanceof globalThis.Headers)
) {
const initialHeaders = init as Headers
initialHeaders.forEach((value, name) => {
Expand Down

0 comments on commit 49a4386

Please sign in to comment.