0.0.9 • Published 4 years ago

@network-stackify/https v0.0.9

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

@network-stackify/https

Drop in replacement for https module

Usage

In nodejs, use like the native https module:

const https = require("@network-stackify/https");

function readResponse(response) {
  var str = "";
  response.on("data", (chunk) => {
    str += chunk;
  });
  response.on("end", () => {
    console.log(str);
  });
}

//Defaults to using native net and tls modules.
https.request("https://google.com", readResponse).end();
https.get("https://google.com", readResponse).end();

//Customize net and/or tls module by passing opts.createConnection
const createConnection = (opts) => {
  return socket;
};

const options = {
  //these options are required and can be omitted when using an agent
  // results in EPERM (piping) or TLS errors if not strictly correct
  path: null,
  port: 443,
  servername: "google.com",
  createConnection,
};

https.get("https://google.com", options, readResponse).end();

//Agent syntax supports slightly modified syntax for passing custom createConnection
https.get("https://google.com", {
  agent: new https.Agent({ createConnection }),
});

Browser

Browser will require custom net and tls implementation like @network-stackify/libp2p-net and @network-stackify/tls.

module.export = {
  resolve: {
    fallback: {
      https: require.resolve("@network-stackify/https"),
      tls: require.resolve("@network-stackify/tls"),
      net: require.resolve("@network-stackify/libp2p-net"),
    },
  },
};
const ws = require("ws");
const libp2p = createInstance();
let client = new ws("wss://endpoint.tld", {
  //Options for libp2p-net
  libp2p,
  multiaddr,
  proto,
  hops,
});

Cross-platform

For easy front-end bundling, network-stackify uses native modules by default. This way, modules can be replaced selectively.

But if using a custom net and tls module for both browser and nodejs, a non-bundling solution is necessary. Overriding defaults can be done by passing opts.connect/createConnection or opts.socket.

//ws implementation with opts.get and opts.createConnection
const ws = require("@network-stackify/ws");

const https = require("@network-stackify/https");
const tls = require("@network-stackify/tls");
const net = require("@network-stackify/libp2p-net");

const libp2p = createInstance(opts);

const createConnection = (opts) => {
  const socket = net.connect(opts);
  return tls.connect({ ...opts, socket });
};

const options = {
  //Override native https.get (in ws)
  get: https.get,

  //Override native tls.connect
  createConnection,

  //these options are required and can be omitted when using an agent
  // results in EPERM (piping) or TLS errors if not strictly correct
  path: null,
  port: 443,
  servername: "google.com",

  //Custom net options
  libp2p,
  multiaddrs,
  hops,
  proto,
};

Contents

Class: https.Agent

https.get(options, callback)

https.get(url, options)

https.globalAgent

https.request(options, callback)

https.request(url, options)

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago