Skip to content

Commit

Permalink
Merge pull request #23 from KentarouTakeda/content-negotiation
Browse files Browse the repository at this point in the history
Fixed OGP acquisition failure due to Content Negotiation
  • Loading branch information
h-sugawara authored Jan 26, 2024
2 parents c0f7f4c + f4a231b commit de13bc8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ function findOptionalArgs(opts, find) {

function getFetchOptions(isCrawler) {
const fetchOptions = {};
const headers = {};
const headers = {
'accept': 'text/html',
};

if (typeof isCrawler === 'boolean' && isCrawler) {
headers['user-agent'] = CRAWLER_USER_AGENT;
Expand Down
4 changes: 3 additions & 1 deletion test/parameters.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('parameters', () => {
url: args[0],
fetchOptions: {
headers: {
'accept': 'text/html',
'user-agent': 'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Chrome/112.0.0.0 Safari/537.36',
},
},
Expand Down Expand Up @@ -43,6 +44,7 @@ describe('parameters', () => {
url: args[0],
fetchOptions: {
headers: {
'accept': 'text/html',
'user-agent': 'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Chrome/112.0.0.0 Safari/537.36',
},
},
Expand All @@ -60,7 +62,7 @@ describe('parameters', () => {

expect(getParameters(args, fallbackText, config)).toEqual(
{
scrape: { url: args[0], fetchOptions: {} },
scrape: { url: args[0], fetchOptions: { headers: { accept: 'text/html' } } },
generate: { target: '_blank', rel: 'nofollow', loading: 'lazy', descriptionLength, className, fallbackText },
}
);
Expand Down

0 comments on commit de13bc8

Please sign in to comment.