https#Agent TypeScript Examples

The following examples show how to use https#Agent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: http.spec.ts    From walletconnect-v2-monorepo with Apache License 2.0 6 votes vote down vote up
describe("HTTP", () => {
  let api: AxiosInstance;
  before(() => {
    api = axios.create({
      httpsAgent: new Agent({
        rejectUnauthorized: false,
      }),
      // Axios sends GET instead of POST when using ws protocol
      baseURL: TEST_HTTP_URL,
      timeout: 30000, // 30 secs
      headers: {
        Accept: "application/json",
        "Content-Type": "application/json",
      },
    });
  });
  it("GET health", async () => {
    const endpoint = formatEndpoint("/health", TEST_PROJECT_ID);
    const response = await api.get(endpoint);
    expect(response.status).to.equal(204);
  });
  it("GET hello", async () => {
    const endpoint = formatEndpoint("/hello", TEST_PROJECT_ID);
    const response = await api.get(endpoint);
    expect(response.status).to.equal(200);
    expect(response.data.startsWith(`Hello World, this is Relay Server`)).to.be.true;
  });
  it("POST subscribe", async () => {
    const payload = { topic: TEST_TOPIC, webhook: "https://example.com" };
    const endpoint = formatEndpoint("/subscribe", TEST_PROJECT_ID);
    const response = await api.post(endpoint, payload);
    expect(response.status).to.equal(200);
    expect(response.data).to.deep.equal({ success: true });
  });
});
Example #2
Source File: RpcClient.ts    From chia-client with MIT License 6 votes vote down vote up
public constructor(options: ChiaOptions) {
    this.hostname = options.hostname;
    this.port =  options.port,
    this.agent = new Agent({
      cert: readFileSync(options.certPath),
      key: readFileSync(options.keyPath),
      rejectUnauthorized: false,
    });
  }
Example #3
Source File: io.ts    From DefinitelyTyped-tools with MIT License 6 votes vote down vote up
function doRequest(options: FetchOptions, makeRequest: typeof request, agent?: Agent): Promise<string> {
  return new Promise((resolve, reject) => {
    const req = makeRequest(
      {
        hostname: options.hostname,
        port: options.port,
        path: `/${options.path}`,
        agent,
        method: options.method || "GET",
        headers: options.headers,
        timeout: options.timeout ?? downloadTimeout,
      },
      (res) => {
        let text = "";
        res.on("data", (d: string) => {
          text += d;
        });
        res.on("error", reject);
        res.on("end", () => {
          resolve(text);
        });
      }
    );
    if (options.body !== undefined) {
      req.write(options.body);
    }
    req.end();
  });
}
Example #4
Source File: google-recaptcha-module.spec.ts    From google-recaptcha with MIT License 5 votes vote down vote up
describe('Google recaptcha module', () => {
    const customNetwork = 'CUSTOM_URL';
    let app: INestApplication;

    beforeAll(async () => {
        const testingModule = await Test.createTestingModule({
            imports: [
                GoogleRecaptchaModule.forRoot({
                    secretKey: process.env.GOOGLE_RECAPTCHA_SECRET_KEY,
                    response: req => req.headers.authorization,
                    skipIf: () => process.env.NODE_ENV !== 'production',
                    network: customNetwork,
                    agent: new Agent({maxFreeSockets: 10}),
                }),
            ],
        }).compile();

        app = testingModule.createNestApplication();
    });

    test('Test validator provider', () => {
        const guard = app.get(GoogleRecaptchaValidator);

        expect(guard).toBeInstanceOf(GoogleRecaptchaValidator);
    });

    test('Test guard provider', () => {
        const guard = app.get(GoogleRecaptchaGuard);

        expect(guard).toBeInstanceOf(GoogleRecaptchaGuard);
    });

    test('Test use recaptcha net options',  async () => {
        const options: GoogleRecaptchaModuleOptions = app.get(RECAPTCHA_OPTIONS);

        expect(options).toBeDefined();
        expect(options.network).toBe(customNetwork);
        expect(options.agent).toBeDefined();
        expect(options.agent).toBeInstanceOf(Agent);
        expect(options.agent.maxFreeSockets).toBe(10);
    });
});
Example #5
Source File: RpcClient.ts    From chia-client with MIT License 5 votes vote down vote up
private readonly agent: Agent;
Example #6
Source File: io.ts    From DefinitelyTyped-tools with MIT License 5 votes vote down vote up
private readonly agent = new Agent({ keepAlive: true });
Example #7
Source File: FetchRequest.ts    From VerifiableCredentials-Verification-SDK-Typescript with MIT License 5 votes vote down vote up
/**
   * Create new instance of FetchRequest
   */
  constructor() {
    this.agent = new Agent({ keepAlive: true });
  }
Example #8
Source File: FetchRequest.ts    From VerifiableCredentials-Verification-SDK-Typescript with MIT License 5 votes vote down vote up
/**
    * Agent instance for connection reuse
    */
  private readonly agent: Agent;