forked from loafle/openapi-generator-original
[typescript] migrate url-parse to URL WHATGW in https.ts (#14319)
* migrate * remove extra blank line
This commit is contained in:
parent
917892db7d
commit
babfdff78a
@ -2,16 +2,11 @@
|
|||||||
{{#node}}
|
{{#node}}
|
||||||
// TODO: evaluate if we can easily get rid of this library
|
// TODO: evaluate if we can easily get rid of this library
|
||||||
import {{^supportsES6}}* as{{/supportsES6}} FormData from "form-data";
|
import {{^supportsES6}}* as{{/supportsES6}} FormData from "form-data";
|
||||||
import { URLSearchParams } from 'url';
|
import { URL, URLSearchParams } from 'url';
|
||||||
import * as http from 'http';
|
import * as http from 'http';
|
||||||
import * as https from 'https';
|
import * as https from 'https';
|
||||||
{{/node}}
|
{{/node}}
|
||||||
{{/platforms}}
|
{{/platforms}}
|
||||||
{{#platforms}}
|
|
||||||
{{^deno}}
|
|
||||||
import {{^supportsES6}}* as{{/supportsES6}} URLParse from "url-parse";
|
|
||||||
{{/deno}}
|
|
||||||
{{/platforms}}
|
|
||||||
import { Observable, from } from {{#useRxJS}}'rxjs'{{/useRxJS}}{{^useRxJS}}'../rxjsStub{{importFileExtension}}'{{/useRxJS}};
|
import { Observable, from } from {{#useRxJS}}'rxjs'{{/useRxJS}}{{^useRxJS}}'../rxjsStub{{importFileExtension}}'{{/useRxJS}};
|
||||||
|
|
||||||
{{#platforms}}
|
{{#platforms}}
|
||||||
@ -57,44 +52,6 @@ export type HttpFile = {{{fileContentDataType}}} & { readonly name: string };
|
|||||||
{{/node}}
|
{{/node}}
|
||||||
{{/platforms}}
|
{{/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 {
|
export class HttpException extends Error {
|
||||||
public constructor(msg: string) {
|
public constructor(msg: string) {
|
||||||
super(msg);
|
super(msg);
|
||||||
@ -112,7 +69,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams;
|
|||||||
export class RequestContext {
|
export class RequestContext {
|
||||||
private headers: { [key: string]: string } = {};
|
private headers: { [key: string]: string } = {};
|
||||||
private body: RequestBody = undefined;
|
private body: RequestBody = undefined;
|
||||||
private url: URLParse;
|
private url: URL;
|
||||||
{{#platforms}}
|
{{#platforms}}
|
||||||
{{#node}}
|
{{#node}}
|
||||||
private agent: http.Agent | https.Agent | undefined = undefined;
|
private agent: http.Agent | https.Agent | undefined = undefined;
|
||||||
@ -126,7 +83,7 @@ export class RequestContext {
|
|||||||
* @param httpMethod http method
|
* @param httpMethod http method
|
||||||
*/
|
*/
|
||||||
public constructor(url: string, private httpMethod: HttpMethod) {
|
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 {
|
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) {
|
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) {
|
public setQueryParam(name: string, value: string) {
|
||||||
let queryObj = this.url.query;
|
this.url.searchParams.set(name, value);
|
||||||
queryObj[name] = value;
|
|
||||||
this.url.set("query", queryObj);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import * as URLParse from "url-parse";
|
|
||||||
import { Observable, from } from '../rxjsStub';
|
import { Observable, from } from '../rxjsStub';
|
||||||
|
|
||||||
export * from './isomorphic-fetch';
|
export * from './isomorphic-fetch';
|
||||||
@ -23,7 +22,6 @@ export enum HttpMethod {
|
|||||||
*/
|
*/
|
||||||
export type HttpFile = Blob & { readonly name: string };
|
export type HttpFile = Blob & { readonly name: string };
|
||||||
|
|
||||||
|
|
||||||
export class HttpException extends Error {
|
export class HttpException extends Error {
|
||||||
public constructor(msg: string) {
|
public constructor(msg: string) {
|
||||||
super(msg);
|
super(msg);
|
||||||
@ -41,7 +39,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams;
|
|||||||
export class RequestContext {
|
export class RequestContext {
|
||||||
private headers: { [key: string]: string } = {};
|
private headers: { [key: string]: string } = {};
|
||||||
private body: RequestBody = undefined;
|
private body: RequestBody = undefined;
|
||||||
private url: URLParse;
|
private url: URL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the request context using a http method and request resource url
|
* Creates the request context using a http method and request resource url
|
||||||
@ -50,7 +48,7 @@ export class RequestContext {
|
|||||||
* @param httpMethod http method
|
* @param httpMethod http method
|
||||||
*/
|
*/
|
||||||
public constructor(url: string, private httpMethod: HttpMethod) {
|
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 {
|
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) {
|
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) {
|
public setQueryParam(name: string, value: string) {
|
||||||
let queryObj = this.url.query;
|
this.url.searchParams.set(name, value);
|
||||||
queryObj[name] = value;
|
|
||||||
this.url.set("query", queryObj);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import URLParse from "url-parse";
|
|
||||||
import { Observable, from } from '../rxjsStub';
|
import { Observable, from } from '../rxjsStub';
|
||||||
|
|
||||||
export * from './isomorphic-fetch';
|
export * from './isomorphic-fetch';
|
||||||
@ -23,7 +22,6 @@ export enum HttpMethod {
|
|||||||
*/
|
*/
|
||||||
export type HttpFile = Blob & { readonly name: string };
|
export type HttpFile = Blob & { readonly name: string };
|
||||||
|
|
||||||
|
|
||||||
export class HttpException extends Error {
|
export class HttpException extends Error {
|
||||||
public constructor(msg: string) {
|
public constructor(msg: string) {
|
||||||
super(msg);
|
super(msg);
|
||||||
@ -41,7 +39,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams;
|
|||||||
export class RequestContext {
|
export class RequestContext {
|
||||||
private headers: { [key: string]: string } = {};
|
private headers: { [key: string]: string } = {};
|
||||||
private body: RequestBody = undefined;
|
private body: RequestBody = undefined;
|
||||||
private url: URLParse;
|
private url: URL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the request context using a http method and request resource url
|
* Creates the request context using a http method and request resource url
|
||||||
@ -50,7 +48,7 @@ export class RequestContext {
|
|||||||
* @param httpMethod http method
|
* @param httpMethod http method
|
||||||
*/
|
*/
|
||||||
public constructor(url: string, private httpMethod: HttpMethod) {
|
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 {
|
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) {
|
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) {
|
public setQueryParam(name: string, value: string) {
|
||||||
let queryObj = this.url.query;
|
this.url.searchParams.set(name, value);
|
||||||
queryObj[name] = value;
|
|
||||||
this.url.set("query", queryObj);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import * as URLParse from "url-parse";
|
|
||||||
import { Observable, from } from '../rxjsStub';
|
import { Observable, from } from '../rxjsStub';
|
||||||
|
|
||||||
export * from './isomorphic-fetch';
|
export * from './isomorphic-fetch';
|
||||||
@ -23,7 +22,6 @@ export enum HttpMethod {
|
|||||||
*/
|
*/
|
||||||
export type HttpFile = Blob & { readonly name: string };
|
export type HttpFile = Blob & { readonly name: string };
|
||||||
|
|
||||||
|
|
||||||
export class HttpException extends Error {
|
export class HttpException extends Error {
|
||||||
public constructor(msg: string) {
|
public constructor(msg: string) {
|
||||||
super(msg);
|
super(msg);
|
||||||
@ -41,7 +39,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams;
|
|||||||
export class RequestContext {
|
export class RequestContext {
|
||||||
private headers: { [key: string]: string } = {};
|
private headers: { [key: string]: string } = {};
|
||||||
private body: RequestBody = undefined;
|
private body: RequestBody = undefined;
|
||||||
private url: URLParse;
|
private url: URL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the request context using a http method and request resource url
|
* Creates the request context using a http method and request resource url
|
||||||
@ -50,7 +48,7 @@ export class RequestContext {
|
|||||||
* @param httpMethod http method
|
* @param httpMethod http method
|
||||||
*/
|
*/
|
||||||
public constructor(url: string, private httpMethod: HttpMethod) {
|
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 {
|
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) {
|
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) {
|
public setQueryParam(name: string, value: string) {
|
||||||
let queryObj = this.url.query;
|
this.url.searchParams.set(name, value);
|
||||||
queryObj[name] = value;
|
|
||||||
this.url.set("query", queryObj);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
// TODO: evaluate if we can easily get rid of this library
|
// TODO: evaluate if we can easily get rid of this library
|
||||||
import * as FormData from "form-data";
|
import * as FormData from "form-data";
|
||||||
import { URLSearchParams } from 'url';
|
import { URL, URLSearchParams } from 'url';
|
||||||
import * as http from 'http';
|
import * as http from 'http';
|
||||||
import * as https from 'https';
|
import * as https from 'https';
|
||||||
import * as URLParse from "url-parse";
|
|
||||||
import { Observable, from } from '../rxjsStub';
|
import { Observable, from } from '../rxjsStub';
|
||||||
|
|
||||||
export * from './isomorphic-fetch';
|
export * from './isomorphic-fetch';
|
||||||
@ -31,7 +30,6 @@ export type HttpFile = {
|
|||||||
name: string
|
name: string
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export class HttpException extends Error {
|
export class HttpException extends Error {
|
||||||
public constructor(msg: string) {
|
public constructor(msg: string) {
|
||||||
super(msg);
|
super(msg);
|
||||||
@ -49,7 +47,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams;
|
|||||||
export class RequestContext {
|
export class RequestContext {
|
||||||
private headers: { [key: string]: string } = {};
|
private headers: { [key: string]: string } = {};
|
||||||
private body: RequestBody = undefined;
|
private body: RequestBody = undefined;
|
||||||
private url: URLParse;
|
private url: URL;
|
||||||
private agent: http.Agent | https.Agent | undefined = undefined;
|
private agent: http.Agent | https.Agent | undefined = undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,7 +57,7 @@ export class RequestContext {
|
|||||||
* @param httpMethod http method
|
* @param httpMethod http method
|
||||||
*/
|
*/
|
||||||
public constructor(url: string, private httpMethod: HttpMethod) {
|
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 {
|
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) {
|
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) {
|
public setQueryParam(name: string, value: string) {
|
||||||
let queryObj = this.url.query;
|
this.url.searchParams.set(name, value);
|
||||||
queryObj[name] = value;
|
|
||||||
this.url.set("query", queryObj);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,40 +21,6 @@ export enum HttpMethod {
|
|||||||
*/
|
*/
|
||||||
export type HttpFile = Blob & { readonly name: string };
|
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 {
|
export class HttpException extends Error {
|
||||||
public constructor(msg: string) {
|
public constructor(msg: string) {
|
||||||
super(msg);
|
super(msg);
|
||||||
@ -72,7 +38,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams;
|
|||||||
export class RequestContext {
|
export class RequestContext {
|
||||||
private headers: { [key: string]: string } = {};
|
private headers: { [key: string]: string } = {};
|
||||||
private body: RequestBody = undefined;
|
private body: RequestBody = undefined;
|
||||||
private url: URLParse;
|
private url: URL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the request context using a http method and request resource url
|
* Creates the request context using a http method and request resource url
|
||||||
@ -81,7 +47,7 @@ export class RequestContext {
|
|||||||
* @param httpMethod http method
|
* @param httpMethod http method
|
||||||
*/
|
*/
|
||||||
public constructor(url: string, private httpMethod: HttpMethod) {
|
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 {
|
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) {
|
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) {
|
public setQueryParam(name: string, value: string) {
|
||||||
let queryObj = this.url.query;
|
this.url.searchParams.set(name, value);
|
||||||
queryObj[name] = value;
|
|
||||||
this.url.set("query", queryObj);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
// TODO: evaluate if we can easily get rid of this library
|
// TODO: evaluate if we can easily get rid of this library
|
||||||
import * as FormData from "form-data";
|
import * as FormData from "form-data";
|
||||||
import { URLSearchParams } from 'url';
|
import { URL, URLSearchParams } from 'url';
|
||||||
import * as http from 'http';
|
import * as http from 'http';
|
||||||
import * as https from 'https';
|
import * as https from 'https';
|
||||||
import * as URLParse from "url-parse";
|
|
||||||
import { Observable, from } from '../rxjsStub';
|
import { Observable, from } from '../rxjsStub';
|
||||||
|
|
||||||
export * from './isomorphic-fetch';
|
export * from './isomorphic-fetch';
|
||||||
@ -31,7 +30,6 @@ export type HttpFile = {
|
|||||||
name: string
|
name: string
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export class HttpException extends Error {
|
export class HttpException extends Error {
|
||||||
public constructor(msg: string) {
|
public constructor(msg: string) {
|
||||||
super(msg);
|
super(msg);
|
||||||
@ -49,7 +47,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams;
|
|||||||
export class RequestContext {
|
export class RequestContext {
|
||||||
private headers: { [key: string]: string } = {};
|
private headers: { [key: string]: string } = {};
|
||||||
private body: RequestBody = undefined;
|
private body: RequestBody = undefined;
|
||||||
private url: URLParse;
|
private url: URL;
|
||||||
private agent: http.Agent | https.Agent | undefined = undefined;
|
private agent: http.Agent | https.Agent | undefined = undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,7 +57,7 @@ export class RequestContext {
|
|||||||
* @param httpMethod http method
|
* @param httpMethod http method
|
||||||
*/
|
*/
|
||||||
public constructor(url: string, private httpMethod: HttpMethod) {
|
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 {
|
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) {
|
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) {
|
public setQueryParam(name: string, value: string) {
|
||||||
let queryObj = this.url.query;
|
this.url.searchParams.set(name, value);
|
||||||
queryObj[name] = value;
|
|
||||||
this.url.set("query", queryObj);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import * as URLParse from "url-parse";
|
|
||||||
import { Observable, from } from '../rxjsStub';
|
import { Observable, from } from '../rxjsStub';
|
||||||
|
|
||||||
export * from './jquery';
|
export * from './jquery';
|
||||||
@ -23,7 +22,6 @@ export enum HttpMethod {
|
|||||||
*/
|
*/
|
||||||
export type HttpFile = Blob & { readonly name: string };
|
export type HttpFile = Blob & { readonly name: string };
|
||||||
|
|
||||||
|
|
||||||
export class HttpException extends Error {
|
export class HttpException extends Error {
|
||||||
public constructor(msg: string) {
|
public constructor(msg: string) {
|
||||||
super(msg);
|
super(msg);
|
||||||
@ -41,7 +39,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams;
|
|||||||
export class RequestContext {
|
export class RequestContext {
|
||||||
private headers: { [key: string]: string } = {};
|
private headers: { [key: string]: string } = {};
|
||||||
private body: RequestBody = undefined;
|
private body: RequestBody = undefined;
|
||||||
private url: URLParse;
|
private url: URL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the request context using a http method and request resource url
|
* Creates the request context using a http method and request resource url
|
||||||
@ -50,7 +48,7 @@ export class RequestContext {
|
|||||||
* @param httpMethod http method
|
* @param httpMethod http method
|
||||||
*/
|
*/
|
||||||
public constructor(url: string, private httpMethod: HttpMethod) {
|
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 {
|
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) {
|
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) {
|
public setQueryParam(name: string, value: string) {
|
||||||
let queryObj = this.url.query;
|
this.url.searchParams.set(name, value);
|
||||||
queryObj[name] = value;
|
|
||||||
this.url.set("query", queryObj);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
// TODO: evaluate if we can easily get rid of this library
|
// TODO: evaluate if we can easily get rid of this library
|
||||||
import * as FormData from "form-data";
|
import * as FormData from "form-data";
|
||||||
import { URLSearchParams } from 'url';
|
import { URL, URLSearchParams } from 'url';
|
||||||
import * as http from 'http';
|
import * as http from 'http';
|
||||||
import * as https from 'https';
|
import * as https from 'https';
|
||||||
import * as URLParse from "url-parse";
|
|
||||||
import { Observable, from } from '../rxjsStub';
|
import { Observable, from } from '../rxjsStub';
|
||||||
|
|
||||||
export * from './isomorphic-fetch';
|
export * from './isomorphic-fetch';
|
||||||
@ -31,7 +30,6 @@ export type HttpFile = {
|
|||||||
name: string
|
name: string
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export class HttpException extends Error {
|
export class HttpException extends Error {
|
||||||
public constructor(msg: string) {
|
public constructor(msg: string) {
|
||||||
super(msg);
|
super(msg);
|
||||||
@ -49,7 +47,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams;
|
|||||||
export class RequestContext {
|
export class RequestContext {
|
||||||
private headers: { [key: string]: string } = {};
|
private headers: { [key: string]: string } = {};
|
||||||
private body: RequestBody = undefined;
|
private body: RequestBody = undefined;
|
||||||
private url: URLParse;
|
private url: URL;
|
||||||
private agent: http.Agent | https.Agent | undefined = undefined;
|
private agent: http.Agent | https.Agent | undefined = undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,7 +57,7 @@ export class RequestContext {
|
|||||||
* @param httpMethod http method
|
* @param httpMethod http method
|
||||||
*/
|
*/
|
||||||
public constructor(url: string, private httpMethod: HttpMethod) {
|
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 {
|
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) {
|
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) {
|
public setQueryParam(name: string, value: string) {
|
||||||
let queryObj = this.url.query;
|
this.url.searchParams.set(name, value);
|
||||||
queryObj[name] = value;
|
|
||||||
this.url.set("query", queryObj);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user