Closed webknjaz closed 4 years ago
Confirmed. It seems better not to send Accept:
header to GitHub. On the other hand, some server requires the header (see #5140). So it would be better to allow to customize it via code or configuration.
Just an idea, linkcheck_request_header
might be helpful for such case:
linkcheck_request_header = {
'*': {'Accept': 'text/html,application/xhtml+xml;q=0.9,*/*;q=0.8',}
'https://github.com': {},
...
}
@tk0miya this looks like a good idea.
Oops, I've overlooked to work for this issue on the 3.0 release... I just set the milestone for this issue now.
Is your feature request related to a problem? Please describe.
Currently,
Accept
HTTP header is hardcoded: https://github.com/sphinx-doc/sphinx/blob/dbefc9865d8c2c4006ed52475d1bff865358cd00/sphinx/builders/linkcheck.py#L111. And when I hit servers that require custom headers, the only option is to add those URLs to the ignore list which is what I'd like to avoid.Describe the solution you'd like
Make HTTP headers configurable.
Describe alternatives you've considered
Adding the affected URL to
linkcheck_ignore
Additional context
We have a GitHub Actions badge in README which then gets embedded into Sphinx docs. Running
linkcheck
used to work but now it doesn't. After some debugging I discovered that if the HTTP query doesn't haveAccept:
HTTP header, it works. But the header that Sphinx injects causes GitHub's server to respond withHTTP/1.1 406 Not Acceptable
. Interestingly, if you open this URL in a browser, it works: https://github.com/cherrypy/cheroot/workflows/Test%20suite/badge.svg. Google Chrome sends the following header:Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
.