Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

feat: add support for fetch API Request interface#68

Open
Phillip9587 wants to merge 1 commit intojshttp:master from
Phillip9587:support-request
Open

feat: add support for fetch API Request interface #68
Phillip9587 wants to merge 1 commit intojshttp:master from
Phillip9587:support-request

Conversation

@Phillip9587
Copy link

@Phillip9587 Phillip9587 commented Feb 12, 2025

Currently, the basic-auth package supports parsing Authorization headers from Node.js IncomingMessage objects. However, with the increasing usage of the Fetch API in modern applications (both in server-side environments like Deno, Cloudflare Workers, and Bun, as well as in edge functions), it would be beneficial to extend support to the Fetch API Request interface.

Use Case

In environments like Cloudflare Workers, Deno, and other serverless platforms, request objects conform to the Fetch API standard rather than the Node.js IncomingMessage format. Supporting Request objects would enable seamless authentication handling in these environments without the need for manual header extraction.

Proposed Solution

Modify basic-auth to accept both IncomingMessage and Fetch API Request objects. The implementation could check for the presence of req.headers.get('authorization') in addition to req.headers['authorization'] (Node.js style).

Alternative Workarounds

Currently, users working with Fetch API-based environments must manually extract the Authorization header before passing it to basic-auth, which adds extra steps and reduces convenience:

const credentials = auth.parse(request.headers.get('authorization'));

Adding native support would improve DX (developer experience) and make basic-auth more flexible for modern runtimes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

AltStyle によって変換されたページ (->オリジナル) /