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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/core/src/lib/FetchUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@
*/

import * as fs from 'fs';
import {fetch as fetchh2, Response as FetchH2Response} from 'fetch-h2';
import {context, Response as FetchH2Response} from 'fetch-h2';
import nodefetch, {Response as NodeFetchResponse} from 'node-fetch';
nohe427 marked this conversation as resolved.
Show resolved Hide resolved

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


class FetchUtils {
private fetchEngine = DEFAULT_FETCH_ENGINE;

Expand Down