How to use the http2.createServer function in http2

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 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 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) => {
github visionmedia / superagent / test / node / pipe.js View on Github external
before(function listen(done) {
  server = http.createServer(app);
  server.listen(0, function listening() {
    base += `:${server.address().port}`;
    done();
  });
});
github visionmedia / superagent / test / node / query.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 sofastack / sofa-rpc-node / lib / server / grpc / server.js View on Github external
_startServer(port) {
    const server = http2.createServer();
    server.once('error', err => { this.emit('error', err); });
    server.on('session', session => { this._handleSocket(session); });
    server.on('stream', (stream, headers) => { this._handleStream(stream, headers); });
    server.listen(port, () => {
      const realPort = server.address().port;
      if (port === this.publishPort && port === 0) {
        this.publishPort = realPort;
      }
      this.logger.info('[RpcServer] server start on %s', realPort);
    });
    return server;
  }

http2

An HTTP/2 client and server implementation

MIT
Latest version published 7 years ago

Package Health Score

53 / 100
Full package analysis