style(typescript): use Headers type (#19697)

This commit is contained in:
Joscha Feth 2024-09-27 07:41:03 +01:00 committed by GitHub
parent 5e2af7203a
commit 36367e79e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 112 additions and 84 deletions

View File

@ -63,6 +63,8 @@ export class HttpException extends Error {
*/
export type RequestBody = undefined | string | FormData | URLSearchParams;
type Headers = Record<string, string>;
function ensureAbsoluteUrl(url: string) {
if (url.startsWith("http://") || url.startsWith("https://")) {
return url;
@ -81,7 +83,7 @@ function ensureAbsoluteUrl(url: string) {
* Represents an HTTP request context
*/
export class RequestContext {
private headers: { [key: string]: string } = {};
private headers: Headers = {};
private body: RequestBody = undefined;
private url: URL;
{{#platforms}}
@ -135,7 +137,7 @@ export class RequestContext {
return this.httpMethod;
}
public getHeaders(): { [key: string]: string } {
public getHeaders(): Headers {
return this.headers;
}
@ -224,7 +226,7 @@ export class SelfDecodingBody implements ResponseBody {
export class ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public headers: Headers,
public body: ResponseBody
) {}
@ -235,8 +237,8 @@ export class ResponseContext {
* Parameter names are converted to lower case
* The first parameter is returned with the key `""`
*/
public getParsedHeader(headerName: string): { [parameter: string]: string } {
const result: { [parameter: string]: string } = {};
public getParsedHeader(headerName: string): Headers {
const result: Headers = {};
if (!this.headers[headerName]) {
return result;
}
@ -316,7 +318,7 @@ export function wrapHttpLibrary(promiseHttpLibrary: PromiseHttpLibrary): HttpLib
export class HttpInfo<T> extends ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public headers: Headers,
public body: ResponseBody,
public data: T,
) {

View File

@ -33,6 +33,8 @@ export class HttpException extends Error {
*/
export type RequestBody = undefined | string | FormData | URLSearchParams;
type Headers = Record<string, string>;
function ensureAbsoluteUrl(url: string) {
if (url.startsWith("http://") || url.startsWith("https://")) {
return url;
@ -44,7 +46,7 @@ function ensureAbsoluteUrl(url: string) {
* Represents an HTTP request context
*/
export class RequestContext {
private headers: { [key: string]: string } = {};
private headers: Headers = {};
private body: RequestBody = undefined;
private url: URL;
@ -93,7 +95,7 @@ export class RequestContext {
return this.httpMethod;
}
public getHeaders(): { [key: string]: string } {
public getHeaders(): Headers {
return this.headers;
}
@ -160,7 +162,7 @@ export class SelfDecodingBody implements ResponseBody {
export class ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public headers: Headers,
public body: ResponseBody
) {}
@ -171,8 +173,8 @@ export class ResponseContext {
* Parameter names are converted to lower case
* The first parameter is returned with the key `""`
*/
public getParsedHeader(headerName: string): { [parameter: string]: string } {
const result: { [parameter: string]: string } = {};
public getParsedHeader(headerName: string): Headers {
const result: Headers = {};
if (!this.headers[headerName]) {
return result;
}
@ -245,7 +247,7 @@ export function wrapHttpLibrary(promiseHttpLibrary: PromiseHttpLibrary): HttpLib
export class HttpInfo<T> extends ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public headers: Headers,
public body: ResponseBody,
public data: T,
) {

View File

@ -33,6 +33,8 @@ export class HttpException extends Error {
*/
export type RequestBody = undefined | string | FormData | URLSearchParams;
type Headers = Record<string, string>;
function ensureAbsoluteUrl(url: string) {
if (url.startsWith("http://") || url.startsWith("https://")) {
return url;
@ -44,7 +46,7 @@ function ensureAbsoluteUrl(url: string) {
* Represents an HTTP request context
*/
export class RequestContext {
private headers: { [key: string]: string } = {};
private headers: Headers = {};
private body: RequestBody = undefined;
private url: URL;
@ -93,7 +95,7 @@ export class RequestContext {
return this.httpMethod;
}
public getHeaders(): { [key: string]: string } {
public getHeaders(): Headers {
return this.headers;
}
@ -160,7 +162,7 @@ export class SelfDecodingBody implements ResponseBody {
export class ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public headers: Headers,
public body: ResponseBody
) {}
@ -171,8 +173,8 @@ export class ResponseContext {
* Parameter names are converted to lower case
* The first parameter is returned with the key `""`
*/
public getParsedHeader(headerName: string): { [parameter: string]: string } {
const result: { [parameter: string]: string } = {};
public getParsedHeader(headerName: string): Headers {
const result: Headers = {};
if (!this.headers[headerName]) {
return result;
}
@ -245,7 +247,7 @@ export function wrapHttpLibrary(promiseHttpLibrary: PromiseHttpLibrary): HttpLib
export class HttpInfo<T> extends ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public headers: Headers,
public body: ResponseBody,
public data: T,
) {

View File

@ -41,6 +41,8 @@ export class HttpException extends Error {
*/
export type RequestBody = undefined | string | FormData | URLSearchParams;
type Headers = Record<string, string>;
function ensureAbsoluteUrl(url: string) {
if (url.startsWith("http://") || url.startsWith("https://")) {
return url;
@ -52,7 +54,7 @@ function ensureAbsoluteUrl(url: string) {
* Represents an HTTP request context
*/
export class RequestContext {
private headers: { [key: string]: string } = {};
private headers: Headers = {};
private body: RequestBody = undefined;
private url: URL;
private agent: http.Agent | https.Agent | undefined = undefined;
@ -102,7 +104,7 @@ export class RequestContext {
return this.httpMethod;
}
public getHeaders(): { [key: string]: string } {
public getHeaders(): Headers {
return this.headers;
}
@ -166,7 +168,7 @@ export class SelfDecodingBody implements ResponseBody {
export class ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public headers: Headers,
public body: ResponseBody
) {}
@ -177,8 +179,8 @@ export class ResponseContext {
* Parameter names are converted to lower case
* The first parameter is returned with the key `""`
*/
public getParsedHeader(headerName: string): { [parameter: string]: string } {
const result: { [parameter: string]: string } = {};
public getParsedHeader(headerName: string): Headers {
const result: Headers = {};
if (!this.headers[headerName]) {
return result;
}
@ -242,7 +244,7 @@ export function wrapHttpLibrary(promiseHttpLibrary: PromiseHttpLibrary): HttpLib
export class HttpInfo<T> extends ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public headers: Headers,
public body: ResponseBody,
public data: T,
) {

View File

@ -33,6 +33,8 @@ export class HttpException extends Error {
*/
export type RequestBody = undefined | string | FormData | URLSearchParams;
type Headers = Record<string, string>;
function ensureAbsoluteUrl(url: string) {
if (url.startsWith("http://") || url.startsWith("https://")) {
return url;
@ -44,7 +46,7 @@ function ensureAbsoluteUrl(url: string) {
* Represents an HTTP request context
*/
export class RequestContext {
private headers: { [key: string]: string } = {};
private headers: Headers = {};
private body: RequestBody = undefined;
private url: URL;
@ -93,7 +95,7 @@ export class RequestContext {
return this.httpMethod;
}
public getHeaders(): { [key: string]: string } {
public getHeaders(): Headers {
return this.headers;
}
@ -160,7 +162,7 @@ export class SelfDecodingBody implements ResponseBody {
export class ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public headers: Headers,
public body: ResponseBody
) {}
@ -171,8 +173,8 @@ export class ResponseContext {
* Parameter names are converted to lower case
* The first parameter is returned with the key `""`
*/
public getParsedHeader(headerName: string): { [parameter: string]: string } {
const result: { [parameter: string]: string } = {};
public getParsedHeader(headerName: string): Headers {
const result: Headers = {};
if (!this.headers[headerName]) {
return result;
}
@ -245,7 +247,7 @@ export function wrapHttpLibrary(promiseHttpLibrary: PromiseHttpLibrary): HttpLib
export class HttpInfo<T> extends ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public headers: Headers,
public body: ResponseBody,
public data: T,
) {

View File

@ -33,6 +33,8 @@ export class HttpException extends Error {
*/
export type RequestBody = undefined | string | FormData | URLSearchParams;
type Headers = Record<string, string>;
function ensureAbsoluteUrl(url: string) {
if (url.startsWith("http://") || url.startsWith("https://")) {
return url;
@ -44,7 +46,7 @@ function ensureAbsoluteUrl(url: string) {
* Represents an HTTP request context
*/
export class RequestContext {
private headers: { [key: string]: string } = {};
private headers: Headers = {};
private body: RequestBody = undefined;
private url: URL;
@ -93,7 +95,7 @@ export class RequestContext {
return this.httpMethod;
}
public getHeaders(): { [key: string]: string } {
public getHeaders(): Headers {
return this.headers;
}
@ -160,7 +162,7 @@ export class SelfDecodingBody implements ResponseBody {
export class ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public headers: Headers,
public body: ResponseBody
) {}
@ -171,8 +173,8 @@ export class ResponseContext {
* Parameter names are converted to lower case
* The first parameter is returned with the key `""`
*/
public getParsedHeader(headerName: string): { [parameter: string]: string } {
const result: { [parameter: string]: string } = {};
public getParsedHeader(headerName: string): Headers {
const result: Headers = {};
if (!this.headers[headerName]) {
return result;
}
@ -245,7 +247,7 @@ export function wrapHttpLibrary(promiseHttpLibrary: PromiseHttpLibrary): HttpLib
export class HttpInfo<T> extends ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public headers: Headers,
public body: ResponseBody,
public data: T,
) {

View File

@ -41,6 +41,8 @@ export class HttpException extends Error {
*/
export type RequestBody = undefined | string | FormData | URLSearchParams;
type Headers = Record<string, string>;
function ensureAbsoluteUrl(url: string) {
if (url.startsWith("http://") || url.startsWith("https://")) {
return url;
@ -52,7 +54,7 @@ function ensureAbsoluteUrl(url: string) {
* Represents an HTTP request context
*/
export class RequestContext {
private headers: { [key: string]: string } = {};
private headers: Headers = {};
private body: RequestBody = undefined;
private url: URL;
private agent: http.Agent | https.Agent | undefined = undefined;
@ -102,7 +104,7 @@ export class RequestContext {
return this.httpMethod;
}
public getHeaders(): { [key: string]: string } {
public getHeaders(): Headers {
return this.headers;
}
@ -166,7 +168,7 @@ export class SelfDecodingBody implements ResponseBody {
export class ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public headers: Headers,
public body: ResponseBody
) {}
@ -177,8 +179,8 @@ export class ResponseContext {
* Parameter names are converted to lower case
* The first parameter is returned with the key `""`
*/
public getParsedHeader(headerName: string): { [parameter: string]: string } {
const result: { [parameter: string]: string } = {};
public getParsedHeader(headerName: string): Headers {
const result: Headers = {};
if (!this.headers[headerName]) {
return result;
}
@ -242,7 +244,7 @@ export function wrapHttpLibrary(promiseHttpLibrary: PromiseHttpLibrary): HttpLib
export class HttpInfo<T> extends ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public headers: Headers,
public body: ResponseBody,
public data: T,
) {

View File

@ -32,6 +32,8 @@ export class HttpException extends Error {
*/
export type RequestBody = undefined | string | FormData | URLSearchParams;
type Headers = Record<string, string>;
function ensureAbsoluteUrl(url: string) {
if (url.startsWith("http://") || url.startsWith("https://")) {
return url;
@ -43,7 +45,7 @@ function ensureAbsoluteUrl(url: string) {
* Represents an HTTP request context
*/
export class RequestContext {
private headers: { [key: string]: string } = {};
private headers: Headers = {};
private body: RequestBody = undefined;
private url: URL;
@ -92,7 +94,7 @@ export class RequestContext {
return this.httpMethod;
}
public getHeaders(): { [key: string]: string } {
public getHeaders(): Headers {
return this.headers;
}
@ -148,7 +150,7 @@ export class SelfDecodingBody implements ResponseBody {
export class ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public headers: Headers,
public body: ResponseBody
) {}
@ -159,8 +161,8 @@ export class ResponseContext {
* Parameter names are converted to lower case
* The first parameter is returned with the key `""`
*/
public getParsedHeader(headerName: string): { [parameter: string]: string } {
const result: { [parameter: string]: string } = {};
public getParsedHeader(headerName: string): Headers {
const result: Headers = {};
if (!this.headers[headerName]) {
return result;
}
@ -233,7 +235,7 @@ export function wrapHttpLibrary(promiseHttpLibrary: PromiseHttpLibrary): HttpLib
export class HttpInfo<T> extends ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public headers: Headers,
public body: ResponseBody,
public data: T,
) {

View File

@ -32,6 +32,8 @@ export class HttpException extends Error {
*/
export type RequestBody = undefined | string | FormData | URLSearchParams;
type Headers = Record<string, string>;
function ensureAbsoluteUrl(url: string) {
if (url.startsWith("http://") || url.startsWith("https://")) {
return url;
@ -43,7 +45,7 @@ function ensureAbsoluteUrl(url: string) {
* Represents an HTTP request context
*/
export class RequestContext {
private headers: { [key: string]: string } = {};
private headers: Headers = {};
private body: RequestBody = undefined;
private url: URL;
@ -92,7 +94,7 @@ export class RequestContext {
return this.httpMethod;
}
public getHeaders(): { [key: string]: string } {
public getHeaders(): Headers {
return this.headers;
}
@ -148,7 +150,7 @@ export class SelfDecodingBody implements ResponseBody {
export class ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public headers: Headers,
public body: ResponseBody
) {}
@ -159,8 +161,8 @@ export class ResponseContext {
* Parameter names are converted to lower case
* The first parameter is returned with the key `""`
*/
public getParsedHeader(headerName: string): { [parameter: string]: string } {
const result: { [parameter: string]: string } = {};
public getParsedHeader(headerName: string): Headers {
const result: Headers = {};
if (!this.headers[headerName]) {
return result;
}
@ -233,7 +235,7 @@ export function wrapHttpLibrary(promiseHttpLibrary: PromiseHttpLibrary): HttpLib
export class HttpInfo<T> extends ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public headers: Headers,
public body: ResponseBody,
public data: T,
) {

View File

@ -41,6 +41,8 @@ export class HttpException extends Error {
*/
export type RequestBody = undefined | string | FormData | URLSearchParams;
type Headers = Record<string, string>;
function ensureAbsoluteUrl(url: string) {
if (url.startsWith("http://") || url.startsWith("https://")) {
return url;
@ -52,7 +54,7 @@ function ensureAbsoluteUrl(url: string) {
* Represents an HTTP request context
*/
export class RequestContext {
private headers: { [key: string]: string } = {};
private headers: Headers = {};
private body: RequestBody = undefined;
private url: URL;
private agent: http.Agent | https.Agent | undefined = undefined;
@ -102,7 +104,7 @@ export class RequestContext {
return this.httpMethod;
}
public getHeaders(): { [key: string]: string } {
public getHeaders(): Headers {
return this.headers;
}
@ -166,7 +168,7 @@ export class SelfDecodingBody implements ResponseBody {
export class ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public headers: Headers,
public body: ResponseBody
) {}
@ -177,8 +179,8 @@ export class ResponseContext {
* Parameter names are converted to lower case
* The first parameter is returned with the key `""`
*/
public getParsedHeader(headerName: string): { [parameter: string]: string } {
const result: { [parameter: string]: string } = {};
public getParsedHeader(headerName: string): Headers {
const result: Headers = {};
if (!this.headers[headerName]) {
return result;
}
@ -242,7 +244,7 @@ export function wrapHttpLibrary(promiseHttpLibrary: PromiseHttpLibrary): HttpLib
export class HttpInfo<T> extends ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public headers: Headers,
public body: ResponseBody,
public data: T,
) {

View File

@ -41,6 +41,8 @@ export class HttpException extends Error {
*/
export type RequestBody = undefined | string | FormData | URLSearchParams;
type Headers = Record<string, string>;
function ensureAbsoluteUrl(url: string) {
if (url.startsWith("http://") || url.startsWith("https://")) {
return url;
@ -52,7 +54,7 @@ function ensureAbsoluteUrl(url: string) {
* Represents an HTTP request context
*/
export class RequestContext {
private headers: { [key: string]: string } = {};
private headers: Headers = {};
private body: RequestBody = undefined;
private url: URL;
private agent: http.Agent | https.Agent | undefined = undefined;
@ -102,7 +104,7 @@ export class RequestContext {
return this.httpMethod;
}
public getHeaders(): { [key: string]: string } {
public getHeaders(): Headers {
return this.headers;
}
@ -166,7 +168,7 @@ export class SelfDecodingBody implements ResponseBody {
export class ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public headers: Headers,
public body: ResponseBody
) {}
@ -177,8 +179,8 @@ export class ResponseContext {
* Parameter names are converted to lower case
* The first parameter is returned with the key `""`
*/
public getParsedHeader(headerName: string): { [parameter: string]: string } {
const result: { [parameter: string]: string } = {};
public getParsedHeader(headerName: string): Headers {
const result: Headers = {};
if (!this.headers[headerName]) {
return result;
}
@ -242,7 +244,7 @@ export function wrapHttpLibrary(promiseHttpLibrary: PromiseHttpLibrary): HttpLib
export class HttpInfo<T> extends ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public headers: Headers,
public body: ResponseBody,
public data: T,
) {

View File

@ -33,6 +33,8 @@ export class HttpException extends Error {
*/
export type RequestBody = undefined | string | FormData | URLSearchParams;
type Headers = Record<string, string>;
function ensureAbsoluteUrl(url: string) {
if (url.startsWith("http://") || url.startsWith("https://")) {
return url;
@ -44,7 +46,7 @@ function ensureAbsoluteUrl(url: string) {
* Represents an HTTP request context
*/
export class RequestContext {
private headers: { [key: string]: string } = {};
private headers: Headers = {};
private body: RequestBody = undefined;
private url: URL;
@ -93,7 +95,7 @@ export class RequestContext {
return this.httpMethod;
}
public getHeaders(): { [key: string]: string } {
public getHeaders(): Headers {
return this.headers;
}
@ -160,7 +162,7 @@ export class SelfDecodingBody implements ResponseBody {
export class ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public headers: Headers,
public body: ResponseBody
) {}
@ -171,8 +173,8 @@ export class ResponseContext {
* Parameter names are converted to lower case
* The first parameter is returned with the key `""`
*/
public getParsedHeader(headerName: string): { [parameter: string]: string } {
const result: { [parameter: string]: string } = {};
public getParsedHeader(headerName: string): Headers {
const result: Headers = {};
if (!this.headers[headerName]) {
return result;
}
@ -245,7 +247,7 @@ export function wrapHttpLibrary(promiseHttpLibrary: PromiseHttpLibrary): HttpLib
export class HttpInfo<T> extends ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public headers: Headers,
public body: ResponseBody,
public data: T,
) {

View File

@ -33,6 +33,8 @@ export class HttpException extends Error {
*/
export type RequestBody = undefined | string | FormData | URLSearchParams;
type Headers = Record<string, string>;
function ensureAbsoluteUrl(url: string) {
if (url.startsWith("http://") || url.startsWith("https://")) {
return url;
@ -44,7 +46,7 @@ function ensureAbsoluteUrl(url: string) {
* Represents an HTTP request context
*/
export class RequestContext {
private headers: { [key: string]: string } = {};
private headers: Headers = {};
private body: RequestBody = undefined;
private url: URL;
@ -93,7 +95,7 @@ export class RequestContext {
return this.httpMethod;
}
public getHeaders(): { [key: string]: string } {
public getHeaders(): Headers {
return this.headers;
}
@ -160,7 +162,7 @@ export class SelfDecodingBody implements ResponseBody {
export class ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public headers: Headers,
public body: ResponseBody
) {}
@ -171,8 +173,8 @@ export class ResponseContext {
* Parameter names are converted to lower case
* The first parameter is returned with the key `""`
*/
public getParsedHeader(headerName: string): { [parameter: string]: string } {
const result: { [parameter: string]: string } = {};
public getParsedHeader(headerName: string): Headers {
const result: Headers = {};
if (!this.headers[headerName]) {
return result;
}
@ -245,7 +247,7 @@ export function wrapHttpLibrary(promiseHttpLibrary: PromiseHttpLibrary): HttpLib
export class HttpInfo<T> extends ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public headers: Headers,
public body: ResponseBody,
public data: T,
) {

View File

@ -41,6 +41,8 @@ export class HttpException extends Error {
*/
export type RequestBody = undefined | string | FormData | URLSearchParams;
type Headers = Record<string, string>;
function ensureAbsoluteUrl(url: string) {
if (url.startsWith("http://") || url.startsWith("https://")) {
return url;
@ -52,7 +54,7 @@ function ensureAbsoluteUrl(url: string) {
* Represents an HTTP request context
*/
export class RequestContext {
private headers: { [key: string]: string } = {};
private headers: Headers = {};
private body: RequestBody = undefined;
private url: URL;
private agent: http.Agent | https.Agent | undefined = undefined;
@ -102,7 +104,7 @@ export class RequestContext {
return this.httpMethod;
}
public getHeaders(): { [key: string]: string } {
public getHeaders(): Headers {
return this.headers;
}
@ -166,7 +168,7 @@ export class SelfDecodingBody implements ResponseBody {
export class ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public headers: Headers,
public body: ResponseBody
) {}
@ -177,8 +179,8 @@ export class ResponseContext {
* Parameter names are converted to lower case
* The first parameter is returned with the key `""`
*/
public getParsedHeader(headerName: string): { [parameter: string]: string } {
const result: { [parameter: string]: string } = {};
public getParsedHeader(headerName: string): Headers {
const result: Headers = {};
if (!this.headers[headerName]) {
return result;
}
@ -242,7 +244,7 @@ export function wrapHttpLibrary(promiseHttpLibrary: PromiseHttpLibrary): HttpLib
export class HttpInfo<T> extends ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public headers: Headers,
public body: ResponseBody,
public data: T,
) {