How to use the fetch-h2.JsonBody 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
if (!this._agent) {
      if (this._debug) {
        console.log('> [debug] re-initializing agent')
      }
      this._initAgent()
    }

    const { body } = opts
    if (this._agent) {
      opts.agent = this._agent
    }

    if (body && typeof body === 'object' && typeof body.pipe !== 'function') {
      opts.headers['Content-Type'] = 'application/json'
      if (shouldUseHttp2(this)) {
        opts.body = new JsonBody(body)
      } else {
        opts.body = JSON.stringify(body)
      }
    }

    if(shouldUseHttp2(this) && body && typeof body === 'object' && typeof body.pipe === 'function') {
      opts.body = new StreamBody(body)
    }

    if (!shouldUseHttp2(this) && opts.body && typeof body.pipe !== 'function') {
      opts.headers['Content-Length'] = Buffer.byteLength(opts.body)
    }

    const handleCompleted = async (res) => {
      currentContext.ongoingFetches--;
      if(currentContext !== this._currContext && currentContext.ongoingFetches <= 0) {
github zeit / now / src / util / agent.js View on Github external
._currContext.ongoingFetches}`
    );

    if (!this._agent) {
      debug('Re-initializing agent');
      this._initAgent();
    }

    const { body } = opts;
    if (this._agent) {
      opts.agent = this._agent;
    }

    if (body && typeof body === 'object' && typeof body.pipe !== 'function') {
      opts.headers['Content-Type'] = 'application/json';
      opts.body = new JsonBody(body);
    }

    if (
      body &&
      typeof body === 'object' &&
      typeof body.pipe === 'function'
    ) {
      opts.body = new StreamBody(body);
    }

    const handleCompleted = async res => {
      currentContext.ongoingFetches--;
      if (
        currentContext !== this._currContext &&
        currentContext.ongoingFetches <= 0
      ) {

fetch-h2

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

MIT
Latest version published 3 years ago

Package Health Score

53 / 100
Full package analysis