How to use http2 - 10 common examples

To help you get started, we’ve selected a few http2 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 graalvm / graaljs / test / parallel / test-http2-respond-file-errors.js View on Github external
statCheck: 'function'
};

const types = {
  boolean: true,
  function: () => {},
  number: 1,
  object: {},
  array: [],
  null: null,
  symbol: Symbol('test')
};

const fname = fixtures.path('elipses.txt');

const server = http2.createServer();

server.on('stream', common.mustCall((stream) => {

  // Check for all possible TypeError triggers on options
  Object.keys(optionsWithTypeError).forEach((option) => {
    Object.keys(types).forEach((type) => {
      if (type === optionsWithTypeError[option]) {
        return;
      }

      common.expectsError(
        () => stream.respondWithFile(fname, {
          'content-type': 'text/plain'
        }, {
          [option]: types[type]
        }),
github graalvm / graaljs / test / parallel / test-http2-respond-errors.js View on Github external
'use strict';
// Flags: --expose-internals

const common = require('../common');
if (!common.hasCrypto)
  common.skip('missing crypto');
const http2 = require('http2');
const { internalBinding } = require('internal/test/binding');
const { Http2Stream } = internalBinding('http2');

const server = http2.createServer();

Http2Stream.prototype.respond = () => 1;
server.on('stream', common.mustCall((stream) => {

  // Send headers
  stream.respond({ 'content-type': 'text/plain' });

  // Should throw if headers already sent
  common.expectsError(
    () => stream.respond(),
    {
      type: Error,
      code: 'ERR_HTTP2_HEADERS_SENT',
      message: 'Response has already been initiated.'
    }
  );
github visionmedia / superagent / test / node / unix-sockets.js View on Github external
before(done => {
    if (fs.existsSync(httpsSockPath) === true) {
      // try unlink if sock file exists
      fs.unlinkSync(httpsSockPath);
    }

    if (process.env.HTTP2_TEST) {
      httpsServer = https.createSecureServer({ key, cert }, app);
    } else {
      httpsServer = https.createServer({ key, cert }, app);
    }

    httpsServer.listen(httpsSockPath, done);
  });
github windyfancy / webcontext / lib / webapplication.js View on Github external
listen() {
    let config=this.config;
    if(config.ssl && config.ssl.enable){
      let sslOptions={
        key: fs.readFileSync(path.resolve(workDirectory,'ssl/privatekey.pem')), // 私钥
        cert: fs.readFileSync(path.resolve(workDirectory,'ssl/certificate.pem')) // 公钥
      }
      const http2 =require('http2');
      var sslServer=http2.createSecureServer(sslOptions, this.createHttpHandler());
      sslServer.listen(config.ssl.port)
    }
    const port=this.config["port"];
    const server = http.createServer(this.createHttpHandler());
    server.listen(port);
  }
github mcollina / h2url / test / basic.js View on Github external
test('http', (t) => {
  const server = http2.createServer()

  server.listen(0, () => {
    server.unref()

    doTests(server, 'http', t.test)
    t.end()
  })
})
github mcollina / h2url / test / basic.js View on Github external
test('https', (t) => {
  const server = http2.createSecureServer({
    key: fs.readFileSync(path.join(__dirname, 'test.key')),
    cert: fs.readFileSync(path.join(__dirname, 'test.cert'))
  })

  server.listen(0, () => {
    server.unref()

    doTests(server, 'https', t.test)
    t.end()
  })
})
github graalvm / graaljs / test / parallel / test-http2-too-large-headers.js View on Github external
'use strict';

const common = require('../common');
if (!common.hasCrypto)
  common.skip('missing crypto');
const http2 = require('http2');
const assert = require('assert');
const {
  NGHTTP2_ENHANCE_YOUR_CALM
} = http2.constants;

const server = http2.createServer({ settings: { maxHeaderListSize: 100 } });
server.on('stream', common.mustNotCall());

server.listen(0, common.mustCall(() => {
  const client = http2.connect(`http://localhost:${server.address().port}`);

  client.on('remoteSettings', () => {
    const req = client.request({ 'foo': 'a'.repeat(1000) });
    req.on('error', common.expectsError({
      code: 'ERR_HTTP2_STREAM_ERROR',
      type: Error,
      message: 'Stream closed with error code NGHTTP2_ENHANCE_YOUR_CALM'
    }));
    req.on('close', common.mustCall(() => {
      assert.strictEqual(req.rstCode, NGHTTP2_ENHANCE_YOUR_CALM);
      server.close();
      client.close();
github visionmedia / superagent / test / node / response-readable-stream.js View on Github external
before(function listen(done) {
  server = http.createServer(app);
  server = server.listen(0, function listening() {
    base += `:${server.address().port}`;
    done();
  });
});
github visionmedia / superagent / test / node / toError.js View on Github external
before(function listen(done) {
  server = http.createServer(app);
  server = server.listen(0, function listening() {
    base += `:${server.address().port}`;
    done();
  });
});
github visionmedia / superagent / test / node / inflate.js View on Github external
before(function listen(done) {
  server = http.createServer(app);
  server = server.listen(0, function listening() {
    base += `:${server.address().port}`;
    done();
  });
});
app.get('/binary', (req, res) => {

http2

An HTTP/2 client and server implementation

MIT
Latest version published 7 years ago

Package Health Score

53 / 100
Full package analysis