How to use the spdy.createAgent function in spdy

To help you get started, we’ve selected a few spdy 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 GraftJS / jschan / crap / spdy-demo.js View on Github external
// write an head after opening a stream
  // means the client receives the pushed stream before
  // move it before res.push to try
  res.writeHead(200);

  res.end('hello world!');
  stream.write('hello world');
});

server.on('connection', function(socket) {
  console.log('muahhaa');
  socket.setted = 'aaa';
});


var agent = spdy.createAgent({
  host: 'localhost',
  port: 1443,
  rejectUnauthorized: false
});

agent.on('push', function(stream) {
  console.log('Push received from parent request', stream.connection.associated.myid);
});

function startConn(myid) {

  var req = https.request({
    host: 'localhost',
    method: 'POST',
    agent: agent,
    path: '/'
github zettajs / zetta / lib / peer_socket.js View on Github external
this.ws = ws;
  this.connectionId = u.query.connectionId;
  this.ws._socket.removeAllListeners('data'); // Remove WebSocket data handler.

  this.ws._socket.on('end', function() {
    clearInterval(self._pingTimer);
    self.emit('end');
  });

  this.ws.on('error', function(err) {
    clearInterval(self._pingTimer);
    self.emit('error', err);
  });


  this.agent = spdy.createAgent(SpdyAgent, {
    host: this.name,
    port: 80,
    socket: this.ws._socket,
    spdy: {
      plain: true,
      ssl: false
    }
  });

  // TODO: Remove this when bug in agent socket removal is fixed.
  this.agent.maxSockets = 150;
  this.agent.on('push', this.onPushData.bind(this));
  this.agent.on('error', function(err) {
    self.close();
    self.emit('error', err);
  });
github GraftJS / jschan / lib / spdy / client.js View on Github external
opts = opts || {};

  if (opts.rejectUnauthorized !== true) {
    opts.rejectUnauthorized = false;
  }

  this.opts = opts;

  this.encoder = encoder(this, channels);

  opts.spdy = opts.spdy || {};
  opts.spdy.maxChunk = 0;
  opts.spdy.decompress = false;
  opts.maxSockets = opts.maxSockets || 4096;

  this.agent = spdy.createAgent(opts);

  this._nextId = 1;
  this._channels = {};
  this._awayting = {};

  var that = this;

  this.agent.on('error', function(err) {
    // if we force close an agent, some random errors might occur
    if (that._closing || that._closed) {
      return;
    }
    that.emit('error', err);
  });
  this.encoder.on('error', this.emit.bind(this, 'error'));
github alphagov / spotlight / app / server.js View on Github external
global.logger = require('./logger');

//App stuff

if (environment.match(/^development/)) {
  environment = 'development';
}

var http = require('http'),
    https = require('https'),
    path = require('path'),
    spdy = require('spdy');

// Use SPDY to talk to backing services. Seems like a great fit, minimise TLS connection
// overhead and multiplex requests to the same limited number of domains.
https.globalAgent = spdy.createAgent({
  host: 'www.google.com',
  port: 443
});

var rootDir = path.join(__dirname, '..');
var app = require('./appBuilder').getApp(environment, rootDir, argv.REQUIRE_BASE_URL);

// Set a port for the app. There are several different ways to do this:
// - In production-like environments we fall back to the config/ directory.
// - On PaaS products like Heroku, we use the $PORT environment variable that they set.
// - When running a Procfile locally (like with Foreman) we need to override $PORT
//   by setting $SPOTLIGHT_PORT, so that our local Nginx connects to the right place.
var port = process.env.SPOTLIGHT_PORT || process.env.PORT || app.get('port');

app.set('port', port);
github watson / http-traceroute / lib / trace.js View on Github external
}

    this.prevUrl = this.currentUrl

    var opts = parseUrl(this.currentUrl)

    opts.method = 'HEAD'
    opts.headers = {
      'Cookie': this.cookies.prepare(this.currentUrl),
      'User-Agent': this.userAgent
    }

    var protocol = opts.protocol === 'https:' ? https : http

    if (opts.protocol === 'https:') {
      opts.agent = spdy.createAgent({
        host: opts.hostname || opts.host,
        port: opts.port || 443
      })

      // There's a case where spdy deadlocks, as it attempts to fall back to http/1.x;
      // see https://github.com/indutny/node-spdy/blob/v3.4.4/lib/spdy/agent.js#L121-L127,
      // https://github.com/indutny/node-spdy/blob/v3.4.4/lib/spdy/agent.js#L157-L160 and
      // https://github.com/indutny/node-spdy/blob/v3.4.4/lib/spdy/agent.js#L66
      // Fix: overwrite `.createSocket()` with node core's,
      // as spdy's `Agent.prototype._getCreateSocket()` is bugged
      opts.agent.createSocket = https.Agent.prototype.createSocket

      // If a custom agent is used, by default all connection-level
      // errors will result in an uncaught exception
      // (See https://github.com/indutny/node-spdy#usage)
      opts.agent.on('error', function (error) {
github kissweb / kiss / test / push.js View on Github external
var http = require('http')
var path = require('path')
var koa = require('koa')

var serve = require('..')

var port = 4401

var server = spdy.createServer({
  ssl: false,
  plain: true,
}).on('request', function (req, res) {
  fn(req, res)
}).listen(port)

var agent = spdy.createAgent({
  host: '127.0.0.1',
  port: port,
  spdy: {
    ssl: false,
    plain: true,
  }
})

agent.on('error', function (err) {
  console.error(err.stack)
  process.exit(1)
})

agent.on('push', function (stream) {
  console.log('pushed: %s', stream.url)
})
github kissweb / kiss / test / acceptance.js View on Github external
var http = require('http')
var path = require('path')
var koa = require('koa')

var serve = require('..')

var port = 4401

var server = spdy.createServer({
  ssl: false,
  plain: true,
}).on('request', function (req, res) {
  fn(req, res)
}).listen(port)

var agent = spdy.createAgent({
  host: '127.0.0.1',
  port: port,
  spdy: {
    ssl: false,
    plain: true,
  }
})

describe('this.body=', function () {
  it('should support custom bodies', function (done) {
    var app = koa()
    app.use(serve(fixture()))
    app.use(function* (next) {
      this.type = 'css'
      this.body = '@import "index.css";'
      this.etag = 'asdf'
github zettajs / zetta / test / test_api.js View on Github external
it('should have a monitor link for bar formatted correctly for SPDY requests', function(done) {
      var a = getHttpServer(app);

      if (!a.address()) a.listen(0);

      var agent = spdy.createAgent({
        host: '127.0.0.1',
        port: a.address().port,
        spdy: {
          plain: true,
          ssl: false
        }
      });

      var request = http.get({
        host: '127.0.0.1',
        port: a.address().port,
        path: url,
        agent: agent
      }, function(response) {

        var buffers = [];
github indutny / bud / test / fixtures.js View on Github external
fixtures.spdyRequest = function spdyRequest(sh, uri, cb) {
  var agent = spdy.createAgent(sh.frontend);
  return fixtures.agentRequest(sh, agent, uri, cb);
};

spdy

Implementation of the SPDY protocol on node.js.

MIT
Latest version published 4 years ago

Package Health Score

76 / 100
Full package analysis