Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
The asset discovery service cannot capture assets protected by authentication. While headers may not help with cookie or session auth, they will at least enable users to use basic auth, proxy auth, or set some other header token to pass their server's auth requirements.
Approach
Allow two options for specifying headers:
Per-snapshot headers via a
requestHeaders
option – if only a single snapshot needs a header, this would be preferred over setting global request headers.Global headers via a
agent.asset-discovery.request-headers
option inside a config file.Per-snapshot headers are merged with global headers. So headers defined in the config file will always be present, even when specifying additional headers per-snapshot.
The headers are set with Puppeteer's
setExtraHTTPHeaders()
method during asset discovery. For redirected assets, the original request's headers are forwarded to the Axios request.Tests
Live site tests cannot be added to the SDK test site due to Netifly restricting authentication to pro plans. The testing server used (http-server) recently added support for basic auth 6 months ago, but hasn't released a new version of the package for almost 2 years. That package was removed in favor of utilizing Express, which is already installed as a dependency, and
express-basic-auth
was added as a dev-dep for testing headers.