[typescript] migrate url-parse to URL WHATGW in https.ts (#14319)

* migrate

* remove extra blank line
This commit is contained in:
David Gamero 2023-01-04 01:35:23 -05:00 committed by GitHub
parent 917892db7d
commit babfdff78a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 67 additions and 158 deletions

View File

@ -2,16 +2,11 @@
{{#node}}
// TODO: evaluate if we can easily get rid of this library
import {{^supportsES6}}* as{{/supportsES6}} FormData from "form-data";
import { URLSearchParams } from 'url';
import { URL, URLSearchParams } from 'url';
import * as http from 'http';
import * as https from 'https';
{{/node}}
{{/platforms}}
{{#platforms}}
{{^deno}}
import {{^supportsES6}}* as{{/supportsES6}} URLParse from "url-parse";
{{/deno}}
{{/platforms}}
import { Observable, from } from {{#useRxJS}}'rxjs'{{/useRxJS}}{{^useRxJS}}'../rxjsStub{{importFileExtension}}'{{/useRxJS}};
{{#platforms}}
@ -57,44 +52,6 @@ export type HttpFile = {{{fileContentDataType}}} & { readonly name: string };
{{/node}}
{{/platforms}}
{{#platforms}}
{{#deno}}
/**
* URLParse Wrapper for Deno
*/
class URLParse {
private url: URL;
constructor(address: string, _parser: boolean) {
this.url = new URL(address);
}
public set(_part: 'query', obj: {[key: string]: string | undefined}) {
for (const key in obj) {
const value = obj[key];
if (value) {
this.url.searchParams.set(key, value);
} else {
this.url.searchParams.set(key, "");
}
}
}
public get query() {
const obj: {[key: string]: string} = {};
for (const [key, value] of this.url.searchParams.entries()) {
obj[key] = value;
}
return obj;
}
public toString() {
return this.url.toString();
}
}
{{/deno}}
{{/platforms}}
export class HttpException extends Error {
public constructor(msg: string) {
super(msg);
@ -112,7 +69,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams;
export class RequestContext {
private headers: { [key: string]: string } = {};
private body: RequestBody = undefined;
private url: URLParse;
private url: URL;
{{#platforms}}
{{#node}}
private agent: http.Agent | https.Agent | undefined = undefined;
@ -126,7 +83,7 @@ export class RequestContext {
* @param httpMethod http method
*/
public constructor(url: string, private httpMethod: HttpMethod) {
this.url = new URLParse(url, true);
this.url = new URL(url);
}
/*
@ -134,7 +91,9 @@ export class RequestContext {
*
*/
public getUrl(): string {
return this.url.toString();
return this.url.toString().endsWith("/") ?
this.url.toString().slice(0, -1)
: this.url.toString();
}
/**
@ -142,7 +101,7 @@ export class RequestContext {
*
*/
public setUrl(url: string) {
this.url = new URLParse(url, true);
this.url = new URL(url);
}
/**
@ -171,9 +130,7 @@ export class RequestContext {
}
public setQueryParam(name: string, value: string) {
let queryObj = this.url.query;
queryObj[name] = value;
this.url.set("query", queryObj);
this.url.searchParams.set(name, value);
}
/**

View File

@ -1,4 +1,3 @@
import * as URLParse from "url-parse";
import { Observable, from } from '../rxjsStub';
export * from './isomorphic-fetch';
@ -23,7 +22,6 @@ export enum HttpMethod {
*/
export type HttpFile = Blob & { readonly name: string };
export class HttpException extends Error {
public constructor(msg: string) {
super(msg);
@ -41,7 +39,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams;
export class RequestContext {
private headers: { [key: string]: string } = {};
private body: RequestBody = undefined;
private url: URLParse;
private url: URL;
/**
* Creates the request context using a http method and request resource url
@ -50,7 +48,7 @@ export class RequestContext {
* @param httpMethod http method
*/
public constructor(url: string, private httpMethod: HttpMethod) {
this.url = new URLParse(url, true);
this.url = new URL(url);
}
/*
@ -58,7 +56,9 @@ export class RequestContext {
*
*/
public getUrl(): string {
return this.url.toString();
return this.url.toString().endsWith("/") ?
this.url.toString().slice(0, -1)
: this.url.toString();
}
/**
@ -66,7 +66,7 @@ export class RequestContext {
*
*/
public setUrl(url: string) {
this.url = new URLParse(url, true);
this.url = new URL(url);
}
/**
@ -95,9 +95,7 @@ export class RequestContext {
}
public setQueryParam(name: string, value: string) {
let queryObj = this.url.query;
queryObj[name] = value;
this.url.set("query", queryObj);
this.url.searchParams.set(name, value);
}
/**

View File

@ -1,4 +1,3 @@
import URLParse from "url-parse";
import { Observable, from } from '../rxjsStub';
export * from './isomorphic-fetch';
@ -23,7 +22,6 @@ export enum HttpMethod {
*/
export type HttpFile = Blob & { readonly name: string };
export class HttpException extends Error {
public constructor(msg: string) {
super(msg);
@ -41,7 +39,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams;
export class RequestContext {
private headers: { [key: string]: string } = {};
private body: RequestBody = undefined;
private url: URLParse;
private url: URL;
/**
* Creates the request context using a http method and request resource url
@ -50,7 +48,7 @@ export class RequestContext {
* @param httpMethod http method
*/
public constructor(url: string, private httpMethod: HttpMethod) {
this.url = new URLParse(url, true);
this.url = new URL(url);
}
/*
@ -58,7 +56,9 @@ export class RequestContext {
*
*/
public getUrl(): string {
return this.url.toString();
return this.url.toString().endsWith("/") ?
this.url.toString().slice(0, -1)
: this.url.toString();
}
/**
@ -66,7 +66,7 @@ export class RequestContext {
*
*/
public setUrl(url: string) {
this.url = new URLParse(url, true);
this.url = new URL(url);
}
/**
@ -95,9 +95,7 @@ export class RequestContext {
}
public setQueryParam(name: string, value: string) {
let queryObj = this.url.query;
queryObj[name] = value;
this.url.set("query", queryObj);
this.url.searchParams.set(name, value);
}
/**

View File

@ -1,4 +1,3 @@
import * as URLParse from "url-parse";
import { Observable, from } from '../rxjsStub';
export * from './isomorphic-fetch';
@ -23,7 +22,6 @@ export enum HttpMethod {
*/
export type HttpFile = Blob & { readonly name: string };
export class HttpException extends Error {
public constructor(msg: string) {
super(msg);
@ -41,7 +39,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams;
export class RequestContext {
private headers: { [key: string]: string } = {};
private body: RequestBody = undefined;
private url: URLParse;
private url: URL;
/**
* Creates the request context using a http method and request resource url
@ -50,7 +48,7 @@ export class RequestContext {
* @param httpMethod http method
*/
public constructor(url: string, private httpMethod: HttpMethod) {
this.url = new URLParse(url, true);
this.url = new URL(url);
}
/*
@ -58,7 +56,9 @@ export class RequestContext {
*
*/
public getUrl(): string {
return this.url.toString();
return this.url.toString().endsWith("/") ?
this.url.toString().slice(0, -1)
: this.url.toString();
}
/**
@ -66,7 +66,7 @@ export class RequestContext {
*
*/
public setUrl(url: string) {
this.url = new URLParse(url, true);
this.url = new URL(url);
}
/**
@ -95,9 +95,7 @@ export class RequestContext {
}
public setQueryParam(name: string, value: string) {
let queryObj = this.url.query;
queryObj[name] = value;
this.url.set("query", queryObj);
this.url.searchParams.set(name, value);
}
/**

View File

@ -1,9 +1,8 @@
// TODO: evaluate if we can easily get rid of this library
import * as FormData from "form-data";
import { URLSearchParams } from 'url';
import { URL, URLSearchParams } from 'url';
import * as http from 'http';
import * as https from 'https';
import * as URLParse from "url-parse";
import { Observable, from } from '../rxjsStub';
export * from './isomorphic-fetch';
@ -31,7 +30,6 @@ export type HttpFile = {
name: string
};
export class HttpException extends Error {
public constructor(msg: string) {
super(msg);
@ -49,7 +47,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams;
export class RequestContext {
private headers: { [key: string]: string } = {};
private body: RequestBody = undefined;
private url: URLParse;
private url: URL;
private agent: http.Agent | https.Agent | undefined = undefined;
/**
@ -59,7 +57,7 @@ export class RequestContext {
* @param httpMethod http method
*/
public constructor(url: string, private httpMethod: HttpMethod) {
this.url = new URLParse(url, true);
this.url = new URL(url);
}
/*
@ -67,7 +65,9 @@ export class RequestContext {
*
*/
public getUrl(): string {
return this.url.toString();
return this.url.toString().endsWith("/") ?
this.url.toString().slice(0, -1)
: this.url.toString();
}
/**
@ -75,7 +75,7 @@ export class RequestContext {
*
*/
public setUrl(url: string) {
this.url = new URLParse(url, true);
this.url = new URL(url);
}
/**
@ -104,9 +104,7 @@ export class RequestContext {
}
public setQueryParam(name: string, value: string) {
let queryObj = this.url.query;
queryObj[name] = value;
this.url.set("query", queryObj);
this.url.searchParams.set(name, value);
}
/**

View File

@ -21,40 +21,6 @@ export enum HttpMethod {
*/
export type HttpFile = Blob & { readonly name: string };
/**
* URLParse Wrapper for Deno
*/
class URLParse {
private url: URL;
constructor(address: string, _parser: boolean) {
this.url = new URL(address);
}
public set(_part: 'query', obj: {[key: string]: string | undefined}) {
for (const key in obj) {
const value = obj[key];
if (value) {
this.url.searchParams.set(key, value);
} else {
this.url.searchParams.set(key, "");
}
}
}
public get query() {
const obj: {[key: string]: string} = {};
for (const [key, value] of this.url.searchParams.entries()) {
obj[key] = value;
}
return obj;
}
public toString() {
return this.url.toString();
}
}
export class HttpException extends Error {
public constructor(msg: string) {
super(msg);
@ -72,7 +38,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams;
export class RequestContext {
private headers: { [key: string]: string } = {};
private body: RequestBody = undefined;
private url: URLParse;
private url: URL;
/**
* Creates the request context using a http method and request resource url
@ -81,7 +47,7 @@ export class RequestContext {
* @param httpMethod http method
*/
public constructor(url: string, private httpMethod: HttpMethod) {
this.url = new URLParse(url, true);
this.url = new URL(url);
}
/*
@ -89,7 +55,9 @@ export class RequestContext {
*
*/
public getUrl(): string {
return this.url.toString();
return this.url.toString().endsWith("/") ?
this.url.toString().slice(0, -1)
: this.url.toString();
}
/**
@ -97,7 +65,7 @@ export class RequestContext {
*
*/
public setUrl(url: string) {
this.url = new URLParse(url, true);
this.url = new URL(url);
}
/**
@ -126,9 +94,7 @@ export class RequestContext {
}
public setQueryParam(name: string, value: string) {
let queryObj = this.url.query;
queryObj[name] = value;
this.url.set("query", queryObj);
this.url.searchParams.set(name, value);
}
/**

View File

@ -1,9 +1,8 @@
// TODO: evaluate if we can easily get rid of this library
import * as FormData from "form-data";
import { URLSearchParams } from 'url';
import { URL, URLSearchParams } from 'url';
import * as http from 'http';
import * as https from 'https';
import * as URLParse from "url-parse";
import { Observable, from } from '../rxjsStub';
export * from './isomorphic-fetch';
@ -31,7 +30,6 @@ export type HttpFile = {
name: string
};
export class HttpException extends Error {
public constructor(msg: string) {
super(msg);
@ -49,7 +47,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams;
export class RequestContext {
private headers: { [key: string]: string } = {};
private body: RequestBody = undefined;
private url: URLParse;
private url: URL;
private agent: http.Agent | https.Agent | undefined = undefined;
/**
@ -59,7 +57,7 @@ export class RequestContext {
* @param httpMethod http method
*/
public constructor(url: string, private httpMethod: HttpMethod) {
this.url = new URLParse(url, true);
this.url = new URL(url);
}
/*
@ -67,7 +65,9 @@ export class RequestContext {
*
*/
public getUrl(): string {
return this.url.toString();
return this.url.toString().endsWith("/") ?
this.url.toString().slice(0, -1)
: this.url.toString();
}
/**
@ -75,7 +75,7 @@ export class RequestContext {
*
*/
public setUrl(url: string) {
this.url = new URLParse(url, true);
this.url = new URL(url);
}
/**
@ -104,9 +104,7 @@ export class RequestContext {
}
public setQueryParam(name: string, value: string) {
let queryObj = this.url.query;
queryObj[name] = value;
this.url.set("query", queryObj);
this.url.searchParams.set(name, value);
}
/**

View File

@ -1,4 +1,3 @@
import * as URLParse from "url-parse";
import { Observable, from } from '../rxjsStub';
export * from './jquery';
@ -23,7 +22,6 @@ export enum HttpMethod {
*/
export type HttpFile = Blob & { readonly name: string };
export class HttpException extends Error {
public constructor(msg: string) {
super(msg);
@ -41,7 +39,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams;
export class RequestContext {
private headers: { [key: string]: string } = {};
private body: RequestBody = undefined;
private url: URLParse;
private url: URL;
/**
* Creates the request context using a http method and request resource url
@ -50,7 +48,7 @@ export class RequestContext {
* @param httpMethod http method
*/
public constructor(url: string, private httpMethod: HttpMethod) {
this.url = new URLParse(url, true);
this.url = new URL(url);
}
/*
@ -58,7 +56,9 @@ export class RequestContext {
*
*/
public getUrl(): string {
return this.url.toString();
return this.url.toString().endsWith("/") ?
this.url.toString().slice(0, -1)
: this.url.toString();
}
/**
@ -66,7 +66,7 @@ export class RequestContext {
*
*/
public setUrl(url: string) {
this.url = new URLParse(url, true);
this.url = new URL(url);
}
/**
@ -95,9 +95,7 @@ export class RequestContext {
}
public setQueryParam(name: string, value: string) {
let queryObj = this.url.query;
queryObj[name] = value;
this.url.set("query", queryObj);
this.url.searchParams.set(name, value);
}
/**

View File

@ -1,9 +1,8 @@
// TODO: evaluate if we can easily get rid of this library
import * as FormData from "form-data";
import { URLSearchParams } from 'url';
import { URL, URLSearchParams } from 'url';
import * as http from 'http';
import * as https from 'https';
import * as URLParse from "url-parse";
import { Observable, from } from '../rxjsStub';
export * from './isomorphic-fetch';
@ -31,7 +30,6 @@ export type HttpFile = {
name: string
};
export class HttpException extends Error {
public constructor(msg: string) {
super(msg);
@ -49,7 +47,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams;
export class RequestContext {
private headers: { [key: string]: string } = {};
private body: RequestBody = undefined;
private url: URLParse;
private url: URL;
private agent: http.Agent | https.Agent | undefined = undefined;
/**
@ -59,7 +57,7 @@ export class RequestContext {
* @param httpMethod http method
*/
public constructor(url: string, private httpMethod: HttpMethod) {
this.url = new URLParse(url, true);
this.url = new URL(url);
}
/*
@ -67,7 +65,9 @@ export class RequestContext {
*
*/
public getUrl(): string {
return this.url.toString();
return this.url.toString().endsWith("/") ?
this.url.toString().slice(0, -1)
: this.url.toString();
}
/**
@ -75,7 +75,7 @@ export class RequestContext {
*
*/
public setUrl(url: string) {
this.url = new URLParse(url, true);
this.url = new URL(url);
}
/**
@ -104,9 +104,7 @@ export class RequestContext {
}
public setQueryParam(name: string, value: string) {
let queryObj = this.url.query;
queryObj[name] = value;
this.url.set("query", queryObj);
this.url.searchParams.set(name, value);
}
/**