Skip to content

Added ClearlyDefined as User-Agent in default header #3

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

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

yashkohli88
Copy link
Owner

No description provided.

@yashkohli88 yashkohli88 force-pushed the yk/add-default-headers-centrally branch from 970f2e9 to 62b0626 Compare October 11, 2024 04:13
class MavenBasedFetch extends AbstractFetch {
constructor(providerMap, options) {
super(options)
this._providerMap = { ...providerMap }
this._handleRequestPromise = options.requestPromise || withDefaults(defaultHeaders)
this._handleRequestPromise = options.requestPromise || callFetch
this._handleRequestStream = options.requestStream || nodeRequest.defaults(defaultHeaders).get
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should be rewritten as
this._handleRequestStream = options.requestStream || nodeRequest.defaults({ headers: defaultHeaders }).get in order to maintain the previous arrangement. Please let me know if this sounds good to you.

Copy link

@qtomlinson qtomlinson Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Your way works! Another way can be

const { callFetch, defaultHeaders: headers } = require('../../lib/fetch')
...

const defaultHeaders = { headers }

Either one works.

Copy link

@qtomlinson qtomlinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

condaFetch has the same header that can be refactored.

class MavenBasedFetch extends AbstractFetch {
constructor(providerMap, options) {
super(options)
this._providerMap = { ...providerMap }
this._handleRequestPromise = options.requestPromise || withDefaults(defaultHeaders)
this._handleRequestPromise = options.requestPromise || callFetch
this._handleRequestStream = options.requestStream || nodeRequest.defaults(defaultHeaders).get
Copy link

@qtomlinson qtomlinson Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Your way works! Another way can be

const { callFetch, defaultHeaders: headers } = require('../../lib/fetch')
...

const defaultHeaders = { headers }

Either one works.

@@ -61,10 +61,7 @@ class PackagistFetch extends AbstractFetch {
if (!distUrl) return request.markSkip('Missing dist.url ')
return new Promise((resolve, reject) => {
const options = {
url: distUrl,
headers: {
'User-Agent': 'clearlydefined.io crawler ([email protected])'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, we have to use imported defaultHeaders

})

it('checks if the default header user-agent is present in packagist components', async () => {
const path = '/api.github.com/repos/php-fig/log/zipball/fe5ea303b0887d5caefd3d431c3e61ad47037001'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can remove test for packagist

@yashkohli88 yashkohli88 force-pushed the yk/add-default-headers-centrally branch from 64cf8bc to 17a52ef Compare October 17, 2024 07:44
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.

3 participants