Michael-F-Bryan / mdbook-linkcheck

A backend for `mdbook` which will check your links for you.
https://michael-f-bryan.github.io/mdbook-linkcheck/
MIT License
145 stars 29 forks source link

Support custom HTTP headers #22

Closed CreepySkeleton closed 4 years ago

CreepySkeleton commented 4 years ago

Some websites (for example crates.io) require certain HTTP headers (for example Accept) to be passed in order to process the request properly.

I propose to allow user to specify the needed headers for URLs matching a certain regexp:

[output.linkcheck]
headers = {
  "https?://crates.io/crate/.*" = "Accept: text/html",
  "example,com" = "Accept: text/xml"
}
Michael-F-Bryan commented 4 years ago

This sounds like a good idea. I'm guessing we can use the #[serde(with = "...")] trick to parse a Table into a list of regex patterns and headers and from there we may need to pull request generation out into its own function instead of using the Client::get() helper so patterns can be applied.

It should also easy to extend to interpolate environment variables for non-public endpoints (e.g. with an Authorization: Basic $GITHUB_TOKEN) if people were interested.