How to use the fetch-h2.context function in fetch-h2

To help you get started, we’ve selected a few fetch-h2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zeit / now / src / providers / sh / util / agent.js View on Github external
async fetch(path, opts = {}) {
    await this._sema.v()

    this._currContext.fetchesMade++;
    if(this._currContext.fetchesMade >= MAX_REQUESTS_PER_CONNECTION) {
      const ctx = context()
      ctx.fetchesMade = 1
      ctx.ongoingFetches = 0
      this._contexts.push(ctx)
      this._currContext = ctx
    }

    // If we're changing contexts, we don't want to record the ongoingFetch on the old context
    // That'll cause an off-by-one error when trying to close the old socket later
    this._currContext.ongoingFetches++;
    const currentContext = this._currContext

    if (this._debug) {
      console.log('> [debug] Total requests made on socket #%d: %d', this._contexts.length, this._currContext.fetchesMade)
      console.log('> [debug] Concurrent requests on socket #%d: %d', this._contexts.length, this._currContext.ongoingFetches)
    }
github zeit / now / src / util / agent.js View on Github external
async fetch(path, opts = {}) {
    const { debug } = this._output;
    await this._sema.v();

    let currentContext;

    this._currContext.fetchesMade++;
    if (this._currContext.fetchesMade >= MAX_REQUESTS_PER_CONNECTION) {
      const ctx = context();
      ctx.fetchesMade = 1;
      ctx.ongoingFetches = 0;
      this._contexts.push(ctx);
      this._currContext = ctx;
    }

    // If we're changing contexts, we don't want to record the ongoingFetch on the old context
    // That'll cause an off-by-one error when trying to close the old socket later
    this._currContext.ongoingFetches++;
    currentContext = this._currContext;

    debug(
      `Total requests made on socket #${this._contexts.length}: ${this
        ._currContext.fetchesMade}`
    );
    debug(
github zeit / now / src / providers / sh / util / agent.js View on Github external
constructor(url, { tls = true, debug } = {}) {
    // We use multiple contexts because each context represent one connection
    // With nginx, we're limited to 1000 requests before a connection is closed
    // http://nginx.org/en/docs/http/ngx_http_v2_module.html#http2_max_requests
    // To get arround this, we keep track of requests made on a connection. when we're about to hit 1000
    // we start up a new connection, and re-route all future traffic through the new connection
    // and when the final request from the old connection resolves, we auto-close the old connection
    this._contexts = [context()]
    this._currContext = this._contexts[0]
    this._currContext.fetchesMade = 0
    this._currContext.ongoingFetches = 0
    
    this._url = url
    const parsed = parse(url)
    this._protocol = parsed.protocol
    this._sema = new Sema(20)
    this._debug = debug
    if (tls) {
      this._initAgent()
    }
  }
github zeit / now / src / util / agent.js View on Github external
constructor(url, { tls = true, debug } = {}) {
    // We use multiple contexts because each context represent one connection
    // With nginx, we're limited to 1000 requests before a connection is closed
    // http://nginx.org/en/docs/http/ngx_http_v2_module.html#http2_max_requests
    // To get arround this, we keep track of requests made on a connection. when we're about to hit 1000
    // we start up a new connection, and re-route all future traffic through the new connection
    // and when the final request from the old connection resolves, we auto-close the old connection
    this._contexts = [context()];
    this._currContext = this._contexts[0];
    this._currContext.fetchesMade = 0;
    this._currContext.ongoingFetches = 0;

    this._url = url;
    const parsed = parse(url);
    this._protocol = parsed.protocol;
    this._sema = new Sema(20);
    this._output = createOutput({ debug });
    if (tls) {
      this._initAgent();
    }
  }

fetch-h2

HTTP/1+2 Fetch API client for Node.js

MIT
Latest version published 2 years ago

Package Health Score

50 / 100
Full package analysis