forked from loafle/openapi-generator-original
[typescript] Adding Custom Agent Support for fetch call (#11400)
* add custom agent support * samples * more samples * merge master files * only enable custom agent on nodejs not browser * samples again * samples * samples once more
This commit is contained in:
parent
24366be0db
commit
b2bb5d071e
@ -3,6 +3,8 @@
|
||||
// TODO: evaluate if we can easily get rid of this library
|
||||
import * as FormData from "form-data";
|
||||
import { URLSearchParams } from 'url';
|
||||
import * as http from 'http';
|
||||
import * as https from 'https';
|
||||
{{/node}}
|
||||
{{/platforms}}
|
||||
{{#platforms}}
|
||||
@ -113,6 +115,11 @@ export class RequestContext {
|
||||
private headers: { [key: string]: string } = {};
|
||||
private body: RequestBody = undefined;
|
||||
private url: URLParse;
|
||||
{{#platforms}}
|
||||
{{#node}}
|
||||
private agent: http.Agent | https.Agent | undefined = undefined;
|
||||
{{/node}}
|
||||
{{/platforms}}
|
||||
|
||||
/**
|
||||
* Creates the request context using a http method and request resource url
|
||||
@ -185,6 +192,18 @@ export class RequestContext {
|
||||
public setHeaderParam(key: string, value: string): void {
|
||||
this.headers[key] = value;
|
||||
}
|
||||
{{#platforms}}
|
||||
{{#node}}
|
||||
|
||||
public setAgent(agent: http.Agent | https.Agent) {
|
||||
this.agent = agent;
|
||||
}
|
||||
|
||||
public getAgent(): http.Agent | https.Agent | undefined {
|
||||
return this.agent;
|
||||
}
|
||||
{{/node}}
|
||||
{{/platforms}}
|
||||
}
|
||||
|
||||
export interface ResponseBody {
|
||||
|
@ -20,6 +20,9 @@ export class IsomorphicFetchHttpLibrary implements HttpLibrary {
|
||||
body: body as any,
|
||||
headers: request.getHeaders(),
|
||||
{{#platforms}}
|
||||
{{#node}}
|
||||
agent: request.getAgent(),
|
||||
{{/node}}
|
||||
{{#browser}}
|
||||
credentials: "same-origin"
|
||||
{{/browser}}
|
||||
|
@ -1,6 +1,8 @@
|
||||
// TODO: evaluate if we can easily get rid of this library
|
||||
import * as FormData from "form-data";
|
||||
import { URLSearchParams } from 'url';
|
||||
import * as http from 'http';
|
||||
import * as https from 'https';
|
||||
// typings of url-parse are incorrect...
|
||||
// @ts-ignore
|
||||
import * as URLParse from "url-parse";
|
||||
@ -50,6 +52,7 @@ export class RequestContext {
|
||||
private headers: { [key: string]: string } = {};
|
||||
private body: RequestBody = undefined;
|
||||
private url: URLParse;
|
||||
private agent: http.Agent | https.Agent | undefined = undefined;
|
||||
|
||||
/**
|
||||
* Creates the request context using a http method and request resource url
|
||||
@ -122,6 +125,14 @@ export class RequestContext {
|
||||
public setHeaderParam(key: string, value: string): void {
|
||||
this.headers[key] = value;
|
||||
}
|
||||
|
||||
public setAgent(agent: http.Agent | https.Agent) {
|
||||
this.agent = agent;
|
||||
}
|
||||
|
||||
public getAgent(): http.Agent | https.Agent | undefined {
|
||||
return this.agent;
|
||||
}
|
||||
}
|
||||
|
||||
export interface ResponseBody {
|
||||
|
@ -12,6 +12,7 @@ export class IsomorphicFetchHttpLibrary implements HttpLibrary {
|
||||
method: method,
|
||||
body: body as any,
|
||||
headers: request.getHeaders(),
|
||||
agent: request.getAgent(),
|
||||
}).then((resp: any) => {
|
||||
const headers: { [name: string]: string } = {};
|
||||
resp.headers.forEach((value: string, name: string) => {
|
||||
|
@ -1,6 +1,8 @@
|
||||
// TODO: evaluate if we can easily get rid of this library
|
||||
import * as FormData from "form-data";
|
||||
import { URLSearchParams } from 'url';
|
||||
import * as http from 'http';
|
||||
import * as https from 'https';
|
||||
// typings of url-parse are incorrect...
|
||||
// @ts-ignore
|
||||
import * as URLParse from "url-parse";
|
||||
@ -50,6 +52,7 @@ export class RequestContext {
|
||||
private headers: { [key: string]: string } = {};
|
||||
private body: RequestBody = undefined;
|
||||
private url: URLParse;
|
||||
private agent: http.Agent | https.Agent | undefined = undefined;
|
||||
|
||||
/**
|
||||
* Creates the request context using a http method and request resource url
|
||||
@ -122,6 +125,14 @@ export class RequestContext {
|
||||
public setHeaderParam(key: string, value: string): void {
|
||||
this.headers[key] = value;
|
||||
}
|
||||
|
||||
public setAgent(agent: http.Agent | https.Agent) {
|
||||
this.agent = agent;
|
||||
}
|
||||
|
||||
public getAgent(): http.Agent | https.Agent | undefined {
|
||||
return this.agent;
|
||||
}
|
||||
}
|
||||
|
||||
export interface ResponseBody {
|
||||
|
@ -12,6 +12,7 @@ export class IsomorphicFetchHttpLibrary implements HttpLibrary {
|
||||
method: method,
|
||||
body: body as any,
|
||||
headers: request.getHeaders(),
|
||||
agent: request.getAgent(),
|
||||
}).then((resp: any) => {
|
||||
const headers: { [name: string]: string } = {};
|
||||
resp.headers.forEach((value: string, name: string) => {
|
||||
|
@ -1,6 +1,8 @@
|
||||
// TODO: evaluate if we can easily get rid of this library
|
||||
import * as FormData from "form-data";
|
||||
import { URLSearchParams } from 'url';
|
||||
import * as http from 'http';
|
||||
import * as https from 'https';
|
||||
// typings of url-parse are incorrect...
|
||||
// @ts-ignore
|
||||
import * as URLParse from "url-parse";
|
||||
@ -50,6 +52,7 @@ export class RequestContext {
|
||||
private headers: { [key: string]: string } = {};
|
||||
private body: RequestBody = undefined;
|
||||
private url: URLParse;
|
||||
private agent: http.Agent | https.Agent | undefined = undefined;
|
||||
|
||||
/**
|
||||
* Creates the request context using a http method and request resource url
|
||||
@ -122,6 +125,14 @@ export class RequestContext {
|
||||
public setHeaderParam(key: string, value: string): void {
|
||||
this.headers[key] = value;
|
||||
}
|
||||
|
||||
public setAgent(agent: http.Agent | https.Agent) {
|
||||
this.agent = agent;
|
||||
}
|
||||
|
||||
public getAgent(): http.Agent | https.Agent | undefined {
|
||||
return this.agent;
|
||||
}
|
||||
}
|
||||
|
||||
export interface ResponseBody {
|
||||
|
@ -12,6 +12,7 @@ export class IsomorphicFetchHttpLibrary implements HttpLibrary {
|
||||
method: method,
|
||||
body: body as any,
|
||||
headers: request.getHeaders(),
|
||||
agent: request.getAgent(),
|
||||
}).then((resp: any) => {
|
||||
const headers: { [name: string]: string } = {};
|
||||
resp.headers.forEach((value: string, name: string) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user