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

refactor(http): Import proper OutgoingHttpHeaders on all http clients #9653

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/datasource/docker/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { OutgoingHttpHeaders } from 'http';
import URL from 'url';
import { ECR } from '@aws-sdk/client-ecr';
import hasha from 'hasha';
Expand All @@ -11,6 +10,7 @@ import { ExternalHostError } from '../../types/errors/external-host-error';
import * as packageCache from '../../util/cache/package';
import * as hostRules from '../../util/host-rules';
import { Http, HttpResponse } from '../../util/http';
import type { OutgoingHttpHeaders } from '../../util/http/types';
import { ensureTrailingSlash, trimTrailingSlash } from '../../util/url';
import * as dockerVersioning from '../../versioning/docker';
import type { GetReleasesConfig, ReleaseResult } from '../types';
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/npm/npmrc.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { OutgoingHttpHeaders } from 'http';
import url from 'url';
import is from '@sindresorhus/is';
import ini from 'ini';
import registryAuthToken from 'registry-auth-token';
import getRegistryUrl from 'registry-auth-token/registry-url';
import { getAdminConfig } from '../../config/admin';
import { logger } from '../../logger';
import type { OutgoingHttpHeaders } from '../../util/http/types';
import { maskToken } from '../../util/mask';
import { add } from '../../util/sanitize';

Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/rubygems/get.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { OutgoingHttpHeaders } from 'http';
import urlJoin from 'url-join';
import { logger } from '../../logger';
import { Http } from '../../util/http';
import type { OutgoingHttpHeaders } from '../../util/http/types';
import type { ReleaseResult } from '../types';
import { id } from './common';

Expand Down
8 changes: 2 additions & 6 deletions lib/util/http/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ import { resolveBaseUrl } from '../url';
import { applyAuthorization, removeAuthorization } from './auth';
import { applyHostRules } from './host-rules';
import { getQueue } from './queue';
import { GotOptions, RequestStats } from './types';
import type { GotOptions, OutgoingHttpHeaders, RequestStats } from './types';

// TODO: refactor code to remove this
import './legacy';

export * from './types';
zharinov marked this conversation as resolved.
Show resolved Hide resolved

interface OutgoingHttpHeaders {
[header: string]: number | string | string[] | undefined;
}

export interface HttpOptions {
body?: any;
username?: string;
Expand Down Expand Up @@ -101,7 +97,7 @@ export class Http<GetOptions = HttpOptions, PostOptions = HttpPostOptions> {
...this.options,
hostType: this.hostType,
...httpOptions,
} as unknown; // TODO: fixme
};
if (process.env.NODE_ENV === 'test') {
options.retry = 0;
}
Expand Down
4 changes: 4 additions & 0 deletions lib/util/http/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ export interface RequestStats {
duration: number;
queueDuration: number;
}

export interface OutgoingHttpHeaders {
Copy link
Member

Choose a reason for hiding this comment

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

We should extend from Record here

[header: string]: string | string[] | undefined;
Copy link
Member

Choose a reason for hiding this comment

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

Remove and add this types to second record type

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Replaced by Record<string, string | string[] | undefined>, because empty interfaces don't lint well

Copy link
Member

Choose a reason for hiding this comment

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

Better use a type def then?

}