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

Enhancement: Allow passing of a custom header for all requests #263

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ Type: `String`
Default value: `'broken-link-checker/0.8.0 Node.js/14.16.0 (OS X; x64)'` (or similar)
The HTTP user-agent to use when checking links as well as retrieving pages and robot exclusions.

### `customHeaders`
Type: `object`
Default value: `{}`
Pass any headers as a global setting such as `{ my-header-dev-tester": "MY_KEY_HERE" }`

## Handling Broken/Excluded Links
A broken link will have an `isBroken` value of `true` and a reason code defined in `brokenReason`. A link that was not checked (emitted as `'junk'`) will have a `wasExcluded` value of `true`, a reason code defined in `excludedReason` and a `isBroken` value of `null`.
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/http-protocol/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const createRequest = (url, auth, method, options, isRetry=false) => new Promise
streamHTTP(url,
{
auth: stringifyAuth(url, auth),
headers: { "user-agent":options.userAgent },
headers: { "user-agent":options.userAgent, ...options.customHeaders },
method,
rejectUnauthorized: false, // accept self-signed SSL certificates
retry: 0,
Expand Down