Options
All
  • Public
  • Public/Protected
  • All
Menu

Module net_utils

Index

Functions

fetch

  • fetch(config: any, url: string, init: undefined | (RequestInit & {})): any
  • fetch a URL. Apart from the first parameter, this implements the Fetch API. (Using this method rather than another enables outputting of curl commands with -c and a couple of defaults suitable for pentf).

    example
    const response = await fetch(config, 'https://example.org/json-api', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify({
            key: 'value',
        }),
    });
    assert.strictEqual(response.status, 200);
    const data = await response.json();
    

    Parameters

    • config: any

      The pentf configuration object.

    • url: string

      URL to fetch.

    • init: undefined | (RequestInit & {})

    Returns any

setupTLSClientAuth

  • setupTLSClientAuth(fetchOptions: Object, keyFilename: string, certFilename: string, rejectUnauthorized?: boolean): Promise<void>
  • Modify fetch options for a request authenticated with a client-side TLS certificate.

    example
    const init = {method: 'POST', body: '{"something": "secret"}'};
    await setupTLSClientAuth(init, 'key.pem', 'cert.crt');
    const response = await fetch(config, 'https://protected.example.org/', init);
    assert.equal(response.status, 200); // 401 = invalid certificate
    

    Parameters

    • fetchOptions: Object

      The fetch request option object to modify. (init parameter in fetch above)

    • keyFilename: string

      Name of the private key file in PEM format (e.g. beginning with -----BEGIN RSA PRIVATE KEY-----)

    • certFilename: string

      Name of the certificate file in PEM format (beginning with -----BEGIN CERTIFICATE-----)

    • rejectUnauthorized: boolean = false

      to validate the server's certificate, false (=default) to accept invalid certificates as well.

    Returns Promise<void>

Generated using TypeDoc