Skip to content

Commit

Permalink
Allow passing of a custom header for all requests
Browse files Browse the repository at this point in the history
Will partly resolve stevenvachon#212

For our use case this prevents the site from tipping DDOS prevention.
  • Loading branch information
khawkins98 committed Jan 8, 2024
1 parent ce9e116 commit dd06f87
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
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

0 comments on commit dd06f87

Please sign in to comment.