Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

spdy-transport

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

spdy-transport - npm Package Compare versions

Comparing version 1.0.0-rc4 to 1.0.0-rc5

30

lib/spdy-transport/connection.js

@@ -514,4 +514,5 @@ 'use strict';

Connection.prototype.request = function request(uri, callback) {
Connection.prototype.reserveStream = function reserveStream(uri, callback) {
var stream = this._createStream(uri);
if (!stream) {

@@ -524,14 +525,3 @@ process.nextTick(function() {

// TODO(indunty): ideally it should just take a stream object as an input
this._spdyState.framer.requestFrame({
id: stream.id,
method: stream.method,
path: stream.path,
host: stream.host,
priority: uri.priority,
headers: stream.headers
}, function(err) {
if (err)
return callback(err);
process.nextTick(function() {
callback(null, stream);

@@ -543,2 +533,16 @@ });

Connection.prototype.request = function request(uri, callback) {
return this.reserveStream(uri, function(err, stream) {
if (err)
return callback(err);
stream.send(function(err) {
if (err)
return callback(err);
callback(null, stream);
});
});
};
Connection.prototype._removeStream = function _removeStream(stream) {

@@ -545,0 +549,0 @@ var state = this._spdyState;

@@ -34,2 +34,10 @@ 'use strict';

PriorityNode.prototype.toJSON = function toJSON() {
return {
parent: this.parent,
weight: this.weight,
exclusive: this.exclusive
};
};
PriorityNode.prototype.getPriority = function getPriority() {

@@ -36,0 +44,0 @@ return this.priority;

@@ -144,2 +144,6 @@ 'use strict';

// Should be already in `:authority`
if (lowName === 'host')
return;
// Do not compress, or index Cookie field (for security reasons)

@@ -146,0 +150,0 @@ var neverIndex = lowName === 'cookie';

@@ -61,5 +61,10 @@ 'use strict';

var lkey = key.toLowerCase();
// Will be in `:host`
if (lkey === 'host' && this.version >= 3)
return false;
return lkey !== 'connection' && lkey !== 'keep-alive' &&
lkey !== 'proxy-connection' && lkey !== 'transfer-encoding';
}).map(function(key) {
}, this).map(function(key) {
var klen = Buffer.byteLength(key),

@@ -66,0 +71,0 @@ value = stringify(loweredHeaders[key]),

@@ -49,2 +49,6 @@ 'use strict';

// Can't send incoming request
// (See `.send()` method)
state.sent = !state.request;
state.readable = options.readable !== false;

@@ -171,2 +175,6 @@ state.writable = options.writable !== false;

// Send the request if it wasn't sent
if (!state.sent)
this.send();
// Writes should come after pending control frames (response and headers)

@@ -302,8 +310,14 @@ if (state.corked !== 0) {

state.framer.dataFrame({
id: this.id,
priority: state.priority.getPriority(),
fin: true,
data: new Buffer(0)
});
// Send the request if it wasn't sent
if (!state.sent) {
// NOTE: will send HEADERS with FIN flag
this.send();
} else {
state.framer.dataFrame({
id: this.id,
priority: state.priority.getPriority(),
fin: true,
data: new Buffer(0)
});
}

@@ -349,3 +363,4 @@ this._maybeClose();

this.emit('pushPromise', push);
if (!this.emit('pushPromise', push))
push.abort();
};

@@ -377,2 +392,44 @@

Stream.prototype.send = function send(callback) {
var state = this._spdyState;
if (state.sent) {
var err = new Error('Stream was already sent');
process.nextTick(function() {
if (callback)
callback(err);
});
return;
}
state.sent = true;
state.timeout.reset();
// GET requests should always be auto-finished
if (this.method === 'GET') {
this._writableState.ended = true;
this._writableState.finished = true;
}
// TODO(indunty): ideally it should just take a stream object as an input
var self = this;
this._hardCork();
state.framer.requestFrame({
id: this.id,
method: this.method,
path: this.path,
host: this.host,
priority: state.priority.toJSON(),
headers: this.headers,
fin: this._writableState.finished
}, function(err) {
self._hardUncork();
if (!callback)
return;
callback(err);
});
};
Stream.prototype.respond = function respond(status, headers, callback) {

@@ -420,2 +477,13 @@ var self = this;

// Request wasn't yet send, coalesce headers
if (!state.sent) {
this.headers = util._extend({}, this.headers);
util._extend(this.headers, headers);
process.nextTick(function() {
if (callback)
callback(null);
});
return;
}
this._hardCork();

@@ -422,0 +490,0 @@ state.framer.headersFrame({

{
"name": "spdy-transport",
"version": "1.0.0-rc4",
"version": "1.0.0-rc5",
"description": "SPDY v2, v3, v3.1 and HTTP2 transport",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -238,3 +238,4 @@ var assert = require('assert');

headers: {
a: 'b'
a: 'b',
host: 'localhost'
}

@@ -241,0 +242,0 @@ }, function(err) {

@@ -51,2 +51,30 @@ var assert = require('assert');

it('should ignore PUSH_PROMISE', function(done) {
client.request({
path: '/parent'
}, function(err, stream) {
assert(!err);
});
server.on('stream', function(stream) {
assert.equal(stream.path, '/parent');
stream.respond(200, {});
stream.pushPromise({
path: '/push',
priority: {
parent: 0,
exclusive: false,
weight: 42
}
}, function(err, stream) {
assert(!err);
stream.once('error', function(err) {
assert(err);
done();
});
});
});
});
it('should fail on disabled PUSH_PROMISE', function(done) {

@@ -53,0 +81,0 @@ client.request({

@@ -63,3 +63,3 @@ var assert = require('assert');

client.request({
method: 'GET',
method: 'POST',
path: '/hello-with-data',

@@ -119,2 +119,3 @@ headers: {

client.request({
method: 'POST',
path: '/hello-with-data'

@@ -148,2 +149,3 @@ }, function(err, stream) {

client.request({
method: 'POST',
path: '/hello-with-data'

@@ -187,3 +189,3 @@ }, function(err, stream) {

client.request({
method: 'GET',
method: 'POST',
path: '/hello-with-data',

@@ -257,3 +259,3 @@ headers: {

client.request({
method: 'GET',
method: 'POST',
path: '/hello-flow',

@@ -331,2 +333,3 @@ headers: {

client.request({
method: 'POST',
path: '/hello-split'

@@ -486,3 +489,133 @@ }, function(err, stream) {

});
it('should reserve and send request', function(done) {
var sent = false;
var received = false;
client.reserveStream({
path: '/hello'
}, function(err, stream) {
assert(!err);
sent = true;
setTimeout(function() {
stream.send(function(err) {
sent = true;
assert(!err);
});
}, 50);
stream.on('response', function(code, headers) {
assert(received);
done();
});
});
server.on('stream', function(stream) {
stream.respond(200, {
});
received = true;
assert(sent);
});
});
it('should coalesce headers in reserved stream', function(done) {
var sent = false;
var received = false;
client.reserveStream({
path: '/hello',
headers: {
normal: 'yes'
}
}, function(err, stream) {
assert(!err);
sent = true;
stream.sendHeaders({ 'not-trailer': 'yay' });
setTimeout(function() {
stream.send(function(err) {
sent = true;
assert(!err);
});
}, 50);
stream.on('response', function(code, headers) {
assert(received);
done();
});
});
server.on('stream', function(stream) {
assert.equal(stream.headers.normal, 'yes')
assert.equal(stream.headers['not-trailer'], 'yay')
stream.respond(200, {
});
received = true;
assert(sent);
});
});
it('should reserve and end request', function(done) {
client.reserveStream({
method: 'PUT',
path: '/hello'
}, function(err, stream) {
assert(!err);
stream.on('error', function() {
// Server will cancel the stream
});
stream.end();
});
server.on('frame', function(frame) {
if (frame.type !== 'HEADERS')
return;
assert.equal(frame.fin, true);
done();
});
});
it('should auto-end GET request', function(done) {
client.reserveStream({
method: 'GET',
path: '/hello'
}, function(err, stream) {
assert(!err);
stream.on('error', function() {
// Server will cancel the stream
});
stream.end();
});
server.on('frame', function(frame) {
if (frame.type !== 'HEADERS')
return;
assert.equal(frame.fin, true);
done();
});
});
it('should send reserved request on write', function(done) {
client.reserveStream({
method: 'POST',
path: '/hello'
}, function(err, stream) {
assert(!err);
stream.end('hello');
});
server.on('stream', function(stream) {
assert.equal(stream.method, 'POST');
expectData(stream, 'hello', done);
});
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc