Skip to content
Browse files

client: fix options handling

* stream: disallow half-open connections
  • Loading branch information...
1 parent e7b9eca commit 2a9001eae9625cb4ed56ab017ddb8354ad873259 @indutny committed Oct 1, 2013
Showing with 77 additions and 3 deletions.
  1. +7 −2 lib/spdy/client.js
  2. +3 −0 lib/spdy/connection.js
  3. +1 −1 lib/spdy/stream.js
  4. +66 −0 test/unit/plain-test.js
View
9 lib/spdy/client.js
@@ -155,7 +155,7 @@ proto.createConnection = function createConnection(options) {
// Close underlying socket and terminate all streams
//
proto.close = function close(callback) {
- this._spdyState.socket.destroy();
+ this._spdyState.socket.destroySoon();
if (callback)
this._spdyState.socket.once('close', callback);
};
@@ -192,8 +192,13 @@ exports.create = function create(base, options) {
}
// Instantiate http server if `ssl: false`
- if (!base && options && options.plain && options.ssl === false)
+ if (!base &&
+ options &&
+ options.spdy &&
+ options.spdy.plain &&
+ options.spdy.ssl === false) {
return exports.create(require('http').Agent, options);
+ }
return new agent(options);
};
View
3 lib/spdy/connection.js
@@ -116,6 +116,9 @@ Connection.prototype._init = function init() {
pool.put(pair);
});
+ // Do not allow half-open connections
+ this.socket.allowHalfOpen = false;
+
if (spdy.utils.isLegacy) {
this.socket.on('drain', function ondrain() {
self.emit('drain');
View
2 lib/spdy/stream.js
@@ -614,7 +614,7 @@ Stream.prototype._write = function write(data, encoding, cb) {
}
// If request was ended - send FIN data frame
- if (finished)
+ if (finished && this._httpMessage.output && !this._httpMessage.output.length)
this.end();
return r;
View
66 test/unit/plain-test.js
@@ -0,0 +1,66 @@
+var assert = require('assert'),
+ spdy = require('../../'),
+ keys = require('../fixtures/keys'),
+ http = require('http'),
+ tls = require('tls'),request
+ Buffer = require('buffer').Buffer,
+ PORT = 8081;
+
+suite('A SPDY Server / Plain', function() {
+ var server;
+ setup(function(done) {
+ server = spdy.createServer({ plain: true, ssl: false }, function(req, res) {
+ res.end('ok');
+ });
+
+ server.listen(PORT, done);
+ });
+
+ teardown(function(done) {
+ server.close(done);
+ });
+
+ test('should respond on regular http requests', function(done) {
+ var req = http.request({
+ host: '127.0.0.1',
+ port: PORT,
+ path: '/',
+ method: 'GET',
+ agent: false,
+ rejectUnauthorized: false
+ }, function(res) {
+ res.on('data', function() {
+ // Ignore incoming data
+ });
+ assert.equal(res.statusCode, 200);
+ done();
+ });
+ req.end();
+ });
+
+ test('should respond on spdy requests', function(done) {
+ var agent = spdy.createAgent({
+ host: '127.0.0.1',
+ port: PORT,
+ spdy: {
+ ssl: false,
+ plain: true,
+ version: 3
+ }
+ });
+
+ var req = http.request({
+ path: '/',
+ method: 'GET',
+ agent: agent,
+ }, function(res) {
+ res.on('data', function() {
+ // Ignore incoming data
+ });
+ assert.equal(res.statusCode, 200);
+ agent.close();
+ done();
+ });
+ req.end();
+ });
+});

0 comments on commit 2a9001e

Please sign in to comment.
Something went wrong with that request. Please try again.