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
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,
) {