How to use the @hapi/wreck.read function in @hapi/wreck

To help you get started, we’ve selected a few @hapi/wreck 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 hapijs / ammo / test / index.js View on Github external
it('emits error on internal processing errors', async () => {

        const random = Buffer.alloc(5000);
        const source = Wreck.toReadableStream(random);
        const stream = new Ammo.Clip({ from: 1000, to: 4000 });

        stream._range = null;         // Force a processing error

        await expect(Wreck.read(source.pipe(stream))).to.reject(Error);
    });
github hapijs / b64 / test / index.js View on Github external
it('flushes remainder', async () => {

        const value = '0123456789';
        const encoded = B64.encode(Buffer.from(value));         // MDEyMzQ1Njc4OQ==

        const stream = new internals.Payload([encoded.slice(0, 14)]);
        const source = stream.pipe(new B64.Decoder());

        const payload = await Wreck.read(source);
        expect(payload.toString()).to.equal(value.toString());
    });
});
github senecajs / seneca / lib / transport.js View on Github external
.then(function(res) {
          var seneca_reply = function(res) {
            // backwards compatibility with seneca-transport
            if (!res.meta$) {
              res.meta$ = {
                id: meta.id
              }
            }

            seneca.reply(internalize_reply(sending_instance, res))
          }

          var wreck_read = Wreck.read(res, spec.wreck.read)
          wreck_read
            .then(function(body) {
              var data = parseJSON(body)

              // JSON cannot handle arbitrary array properties
              if (Array.isArray(data.array$)) {
                var array_data = data.array$
                array_data.meta$ = data.meta$
                data = array_data
              }

              seneca_reply(data)
            })
            .catch(seneca_reply)
        })
        .catch(function(err) {
github elastic / kibana / x-pack / legacy / plugins / code / server / distributed / multinode / non_code_node_adapter.ts View on Github external
async requestFn(baseUrl: string, path: string, payload: RequestPayload, originRequest: Request) {
    const opt = {
      baseUrl,
      payload: JSON.stringify(payload),
      // redirect all headers to CodeNode
      headers: { ...filterHeaders(originRequest), 'kbn-xsrf': 'kibana' },
    };
    const promise = Wreck.request('POST', path, opt);
    const res: http.IncomingMessage = await promise;
    this.log.debug(`sending RPC call to ${baseUrl}${path} ${res.statusCode}`);
    if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
      const buffer: Buffer = await Wreck.read(res, {});
      try {
        return JSON.parse(buffer.toString(), (key, value) => {
          return value && value.type === 'Buffer' ? Buffer.from(value.data) : value;
        });
      } catch (e) {
        this.log.error('parse json failed: ' + buffer.toString());
        throw Boom.boomify(e, { statusCode: 500 });
      }
    } else {
      this.log.error(
        `received ${res.statusCode} from ${baseUrl}/${path}, params was ${util.inspect(
          payload.params
        )}`
      );
      const body: Boom.Payload = await Wreck.read(res, { json: true });
      throw new Boom(body.message, { statusCode: res.statusCode || 500, data: body.error });
github hapijs / pez / test / index.js View on Github external
dispenser.on('part', async (part) => {

        const payload = await Wreck.read(part);
        set(part.name, payload.toString(), part.headers, part.filename);
    });
github glennjones / hapi-swagger / test / helper.js View on Github external
helper.replyWithJSON = async (err, res) => {
  const { payload } = await Wreck.read(res, { json: true });
  return payload;
};
github hapijs / hapi / test / request.js View on Github external
await server.start();

            const options = {
                hostname: 'localhost',
                port: server.info.port,
                path: 'http://example.com/path?a=1&a=2#ignore',
                method: 'GET'
            };

            const team = new Teamwork();
            const req = Http.request(options, (res) => team.attend(res));
            req.end();

            const res = await team.work;
            const payload = await Wreck.read(res);
            expect(payload.toString()).to.equal('1,2');

            await server.stop();
        });
    });
github hapijs / hapi / test / core.js View on Github external
const server = Hapi.server({ routes: { timeout: { socket: false } } });
        server.route({ method: 'GET', path: '/', handler: () => null });

        await server.start();

        let timeout;
        const orig = Net.Socket.prototype.setTimeout;
        Net.Socket.prototype.setTimeout = function (...args) {

            timeout = 'gotcha';
            Net.Socket.prototype.setTimeout = orig;
            return orig.apply(this, args);
        };

        const res = await Wreck.request('GET', 'http://localhost:' + server.info.port + '/');
        await Wreck.read(res);
        expect(timeout).to.equal('gotcha');
        await server.stop();
    });
github elastic / kibana / x-pack / legacy / plugins / code / server / distributed / multinode / non_code_node_adapter.ts View on Github external
const buffer: Buffer = await Wreck.read(res, {});
      try {
        return JSON.parse(buffer.toString(), (key, value) => {
          return value && value.type === 'Buffer' ? Buffer.from(value.data) : value;
        });
      } catch (e) {
        this.log.error('parse json failed: ' + buffer.toString());
        throw Boom.boomify(e, { statusCode: 500 });
      }
    } else {
      this.log.error(
        `received ${res.statusCode} from ${baseUrl}/${path}, params was ${util.inspect(
          payload.params
        )}`
      );
      const body: Boom.Payload = await Wreck.read(res, { json: true });
      throw new Boom(body.message, { statusCode: res.statusCode || 500, data: body.error });
    }
  }
}
github ExpediaGroup / service-client / lib / http / read.js View on Github external
const read = async function (response, options) {
  debug('read(): payload read')
  return Wreck.read(response, options)
}

@hapi/wreck

HTTP Client Utilities

BSD-3-Clause
Latest version published 7 months ago

Package Health Score

82 / 100
Full package analysis