Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't change User-Agent to prevent preflight request. #226

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hamano
Copy link

@hamano hamano commented Jun 9, 2022

Hi, I found a weired issue.
rss-parser does not fetch feed that is hosted github.io with Firefox, but no problem with Chrome.
github.io responds Access-Control-Allow-Origin: * as expected.
The cause was that Firefox was sending a CORS preflight request.
There are several conditions for sending a preflight request, one of which is User-Agent changing.
https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#examples_of_access_control_scenarios

I think many people will be bothered by this issue, so
I recommend not to set User-Agent by default.

@rbren
Copy link
Owner

rbren commented Jun 15, 2022

Hmm. If I remember correctly, when running server-side, we need to add a User-Agent header for a lot of feeds to work. So this could be a breaking change.

Does passing in the option {headers: {'User-Agent': ''}} reset to using the browser's user agent?

@hamano
Copy link
Author

hamano commented Jun 22, 2022

@rbren thanks for the reply.
I tryied: {headers: {'User-Agent': ''}} and {headers: {'User-Agent': null}} but they didn't works.
I've put test file here, please try with Firefox: https://www.osstech.co.jp/~hamano/test.html

@rbren
Copy link
Owner

rbren commented Jun 22, 2022

OK, I think this might be a better solution (untested pseudocode):

let headers = {
  'User-Agent': 'rss-parser',
}
if (typeof window !== 'undefined' && window.navigator && window.navigator.userAgent) {
  headers['User-Agent'] = window.navigator.userAgent;
}

This way we won't create a breaking change for server-side rss-parser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants