-
Notifications
You must be signed in to change notification settings - Fork 166
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
Set a default user-agent #639
Conversation
This changes the user agent that is being sent to sites to match that of a browser. Some sites were blocking our requests because of the default user agent. node-fetch has some issues when attempting to set the user agent, so this was left alone for now, especially because in #552 there is a mention of potentially removing the user agent.
import nodefetch, {Response as NodeFetchResponse} from 'node-fetch'; | ||
|
||
export type FetchEngine = 'node-fetch' | 'fetch-h2'; | ||
const DEFAULT_FETCH_ENGINE: FetchEngine = 'fetch-h2'; | ||
|
||
export type NodeFetchOrFetchH2Response = FetchH2Response | NodeFetchResponse; | ||
|
||
const userAgent = 'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0'; | ||
const fetchh2Ctx = context({userAgent: userAgent, overwriteUserAgent: true}); | ||
const fetchh2 = fetchh2Ctx.fetch; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are fetchh2Ctx
and fetchh2
used anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, line 41 is where fetchh2
is used and fetchh2Ctx
is used to generate the fetch call. Maybe we should collapse line 27 and 28 together?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right, you were previously importing something as fetchh2
but now you're creating a variable of the same name. Sorry I missed that
import nodefetch, {Response as NodeFetchResponse} from 'node-fetch'; | ||
|
||
export type FetchEngine = 'node-fetch' | 'fetch-h2'; | ||
const DEFAULT_FETCH_ENGINE: FetchEngine = 'fetch-h2'; | ||
|
||
export type NodeFetchOrFetchH2Response = FetchH2Response | NodeFetchResponse; | ||
|
||
const userAgent = 'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0'; | ||
const fetchh2Ctx = context({userAgent: userAgent, overwriteUserAgent: true}); | ||
const fetchh2 = fetchh2Ctx.fetch; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right, you were previously importing something as fetchh2
but now you're creating a variable of the same name. Sorry I missed that
This changes the user agent that is being sent to sites to match that of
a browser. Some sites were blocking our requests because of the default
user agent. node-fetch has some issues when attempting to set the user
agent, so this was left alone for now, especially because in #552 there
is a mention of potentially removing the user agent.