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

Set a default user-agent #639

Merged
merged 2 commits into from
Jan 31, 2022
Merged

Set a default user-agent #639

merged 2 commits into from
Jan 31, 2022

Conversation

nohe427
Copy link
Collaborator

@nohe427 nohe427 commented Jan 13, 2022

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.

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.
@nohe427 nohe427 requested a review from PEConn January 26, 2022 16:51
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;
Copy link
Collaborator

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?

Copy link
Collaborator Author

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?

Copy link
Collaborator

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;
Copy link
Collaborator

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

@nohe427 nohe427 merged commit 388e8f4 into main Jan 31, 2022
@andreban andreban added the bug Something isn't working label Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants