Fixed a case where OGP could not be scraped from URLs that supported Content Negotiation. This has been occurring since version 6 and was not a problem in versions 5 and below.
I guess this is caused by the change "Replace GOT with fetch!" in version 6.
Detail and Solution
The cause is that when performing fetch() to the target URL, the Accept header is not specified, so a response whose Content-Type is not text/htnl may be returned. In this case, the request was successful and no error occurred, but all OGPs that should be returned were empty.
The above example is a request using curl, but if we use fetch() without specifying an HTTP header, json will be returned in the same way and OGP acquisition will fail.
The Content-Type required when obtaining OGP is text/html, so specifying it in the Accept header will solve this problem.
The same modification was made to the execution of fetch().
Note
It seems that the CI test was not passed on the master branch from which I branched. Since the exact same test result (failure) was obtained before and after the pull request was created, I have not fixed anything regarding the test failure in this pull request.
Summary
Fixed a case where OGP could not be scraped from URLs that supported Content Negotiation. This has been occurring since version
6
and was not a problem in versions5
and below.I guess this is caused by the change "Replace
GOT
with fetch!" in version6
.Detail and Solution
The cause is that when performing
fetch()
to the target URL, theAccept
header is not specified, so a response whoseContent-Type
is nottext/htnl
may be returned. In this case, the request was successful and no error occurred, but all OGPs that should be returned were empty.For example, let's take a look at the URL to retrieving the README.md of this repository.
The above example is a request using
curl
, but if we usefetch()
without specifying an HTTP header, json will be returned in the same way and OGP acquisition will fail.The
Content-Type
required when obtaining OGP istext/html
, so specifying it in theAccept
header will solve this problem.The same modification was made to the execution of
fetch()
.Note
It seems that the CI test was not passed on the
master
branch from which I branched. Since the exact same test result (failure) was obtained before and after the pull request was created, I have not fixed anything regarding the test failure in this pull request.