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] Adding Custom Agent Support for fetch call #11400

Merged
merged 9 commits into from
Jan 28, 2022
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 @@ -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}}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down