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

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

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
davidgamero marked this conversation as resolved.
Show resolved Hide resolved
{{/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}}
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -126,23 +83,25 @@ 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);
}

/*
* Returns the url set in the constructor including the query string
*
*/
public getUrl(): string {
return this.url.toString();
return this.url.toString().endsWith("/") ?
this.url.toString().slice(0, -1)
: this.url.toString();
}

/**
* Replaces the url set in the constructor with this url.
*
*/
public setUrl(url: string) {
this.url = new URLParse(url, true);
this.url = new URL(url);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as URLParse from "url-parse";
import { Observable, from } from '../rxjsStub';

export * from './isomorphic-fetch';
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -50,23 +48,25 @@ 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);
}

/*
* Returns the url set in the constructor including the query string
*
*/
public getUrl(): string {
return this.url.toString();
return this.url.toString().endsWith("/") ?
this.url.toString().slice(0, -1)
: this.url.toString();
}

/**
* Replaces the url set in the constructor with this url.
*
*/
public setUrl(url: string) {
this.url = new URLParse(url, true);
this.url = new URL(url);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import URLParse from "url-parse";
import { Observable, from } from '../rxjsStub';

export * from './isomorphic-fetch';
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -50,23 +48,25 @@ 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);
}

/*
* Returns the url set in the constructor including the query string
*
*/
public getUrl(): string {
return this.url.toString();
return this.url.toString().endsWith("/") ?
this.url.toString().slice(0, -1)
: this.url.toString();
}

/**
* Replaces the url set in the constructor with this url.
*
*/
public setUrl(url: string) {
this.url = new URLParse(url, true);
this.url = new URL(url);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as URLParse from "url-parse";
import { Observable, from } from '../rxjsStub';

export * from './isomorphic-fetch';
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -50,23 +48,25 @@ 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);
}

/*
* Returns the url set in the constructor including the query string
*
*/
public getUrl(): string {
return this.url.toString();
return this.url.toString().endsWith("/") ?
this.url.toString().slice(0, -1)
: this.url.toString();
}

/**
* Replaces the url set in the constructor with this url.
*
*/
public setUrl(url: string) {
this.url = new URLParse(url, true);
this.url = new URL(url);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -31,7 +30,6 @@ export type HttpFile = {
name: string
};


export class HttpException extends Error {
public constructor(msg: string) {
super(msg);
Expand All @@ -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;

/**
Expand All @@ -59,23 +57,25 @@ 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);
}

/*
* Returns the url set in the constructor including the query string
*
*/
public getUrl(): string {
return this.url.toString();
return this.url.toString().endsWith("/") ?
this.url.toString().slice(0, -1)
: this.url.toString();
}

/**
* Replaces the url set in the constructor with this url.
*
*/
public setUrl(url: string) {
this.url = new URLParse(url, true);
this.url = new URL(url);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down
Loading