Socket
Socket
Sign inDemoInstall

http2-protocol

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http2-protocol - npm Package Compare versions

Comparing version 0.9.0 to 0.9.1

63

example/client.js
var fs = require('fs');
var path = require('path');
var parse_url = require('url').parse;
var http2 = require('..');
var tls = require('tls');
http2.globalAgent = new http2.Agent({
log: require('../test/util').createLogger('client')
});
// Advertised protocol version
var implementedVersion = 'HTTP-draft-09/2.0';
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
// Bunyan logger
var log = require('../test/util').createLogger('client');
// Sending the request
// It would be `var request = http2.get(process.argv.pop());` if we wouldn't care about plain mode
var options = require('url').parse(process.argv.pop());
options.plain = Boolean(process.env.HTTP2_PLAIN);
var request = http2.request(options);
request.end();
// Parsing the URL
var url = parse_url(process.argv.pop())
// Receiving the response
request.on('response', function(response) {
response.pipe(process.stdout);
response.on('end', finish);
});
// Connecting to the server
var socket = tls.connect(url.port, url.hostname, {
rejectUnauthorized: false,
ALPNProtocols: [implementedVersion],
NPNProtocols: [implementedVersion],
servername: url.hostname
}, onConnection);
// Receiving push streams
request.on('push', function(pushRequest) {
var filename = path.join(__dirname, '/push-' + push_count);
push_count += 1;
console.error('Receiving pushed resource: ' + pushRequest.url + ' -> ' + filename);
pushRequest.on('response', function(pushResponse) {
pushResponse.pipe(fs.createWriteStream(filename)).on('finish', finish);
// Handling the connection
function onConnection() {
var endpoint = new http2.Endpoint(log, 'CLIENT', {});
endpoint.pipe(socket).pipe(endpoint);
// Sending request
var stream = endpoint.createStream();
stream.headers({
':method': 'GET',
':scheme': url.protocol.slice(0, url.protocol.length - 1),
':authority': url.hostname,
':path': url.path + (url.hash || '')
});
});
// Receiving push streams
stream.on('promise', function(push_stream, req_headers) {
var filename = path.join(__dirname, '/push-' + push_count);
push_count += 1;
console.error('Receiving pushed resource: ' + req_headers[':path'] + ' -> ' + filename);
push_stream.pipe(fs.createWriteStream(filename)).on('finish', finish);
});
// Receiving the response body
stream.pipe(process.stdout);
stream.on('end', finish);
}
// Quitting after both the response and the associated pushed resources have arrived

@@ -35,0 +52,0 @@ var push_count = 0;

var fs = require('fs');
var path = require('path');
var http2 = require('..');
var tls = require('tls');
var options = process.env.HTTP2_PLAIN ? {
plain: true
} : {
key: fs.readFileSync(path.join(__dirname, '/localhost.key')),
cert: fs.readFileSync(path.join(__dirname, '/localhost.crt'))
};
var exists = fs.existsSync;
var stat = fs.statSync;
var read = fs.createReadStream;
var join = path.join;
// Passing bunyan logger (optional)
options.log = require('../test/util').createLogger('server');
// Advertised protocol version
var implementedVersion = 'HTTP-draft-09/2.0';
// Bunyan logger
var log = require('../test/util').createLogger('server');
// We cache one file to be able to do simple performance tests without waiting for the disk

@@ -20,31 +22,51 @@ var cachedFile = fs.readFileSync(path.join(__dirname, './server.js'));

// Creating the server
var server = http2.createServer(options, function(request, response) {
var filename = path.join(__dirname, request.url);
tls.createServer({
ALPNProtocols: [implementedVersion],
NPNProtocols: [implementedVersion],
key: fs.readFileSync(path.join(__dirname, '/localhost.key')),
cert: fs.readFileSync(path.join(__dirname, '/localhost.crt'))
}).on('secureConnection', onConnection).listen(process.env.HTTP2_PORT || 8080);
// Serving server.js from cache. Useful for microbenchmarks.
if (request.url === cachedUrl) {
response.end(cachedFile);
}
// Handling incoming connections
function onConnection(socket) {
var endpoint = new http2.Endpoint(log, 'SERVER', {});
endpoint.pipe(socket).pipe(endpoint);
// Reading file from disk if it exists and is safe.
else if ((filename.indexOf(__dirname) === 0) && fs.existsSync(filename) && fs.statSync(filename).isFile()) {
response.writeHead('200');
endpoint.on('stream', function(stream) {
stream.on('headers', function(headers) {
var path = headers[':path'];
var filename = join(__dirname, path);
// If they download the certificate, push the private key too, they might need it.
if (response.push && request.url === '/localhost.crt') {
var push = response.push('/localhost.key');
push.writeHead(200);
fs.createReadStream(path.join(__dirname, '/localhost.key')).pipe(push);
}
// Serving server.js from cache. Useful for microbenchmarks.
if (path == cachedUrl) {
stream.headers({ ':status': 200 });
stream.end(cachedFile);
}
fs.createReadStream(filename).pipe(response);
}
// Reading file from disk if it exists and is safe.
else if ((filename.indexOf(__dirname) === 0) && exists(filename) && stat(filename).isFile()) {
stream.headers({ ':status': 200 });
// Otherwise responding with 404.
else {
response.writeHead('404');
response.end();
}
});
// If they download the certificate, push the private key too, they might need it.
if (path === '/localhost.crt') {
var push = stream.promise({
':method': 'GET',
':scheme': headers[':scheme'],
':authority': headers[':authority'],
':path': '/localhost.key'
});
push.headers({ ':status': 200 });
read(join(__dirname, '/localhost.key')).pipe(push);
}
server.listen(process.env.HTTP2_PORT || 8080);
read(filename).pipe(stream);
}
// Otherwise responding with 404.
else {
stream.headers({ ':status': 404 });
stream.end();
}
});
});
}
Version history
===============
### 0.9.1 (2014-01-11) ###
* Updated the examples (#5)
* Fixed a compression error (#6)
* Removed docs from the tree (but they remain [hosted on the github-page])
* [Tarball](https://github.com/molnarg/node-http2-protocol/archive/node-http2-protocol-0.9.1.tar.gz)
[hosted on the github-page]: http://molnarg.github.io/node-http2-protocol/doc/
### 0.9.0 (2013-12-25) ###

@@ -5,0 +14,0 @@

@@ -126,3 +126,3 @@ // The implementation of the [HTTP/2 Header Compression][http2-compression] spec is separated from

this._size -= dropped._size;
droppedEntries[droppedEntries] = dropped;
droppedEntries[dropPoint] = dropped;
}

@@ -492,2 +492,3 @@ return droppedEntries;

for (droppedIndex in droppedEntries) {
droppedIndex = Number(droppedIndex)
var dropped = droppedEntries[droppedIndex];

@@ -494,0 +495,0 @@ if (dropped.keep) {

@@ -14,2 +14,4 @@ // The framer consists of two [Transform Stream][1] subclasses that operate in [object mode][2]:

var MAX_PAYLOAD_SIZE = 16383;
// Serializer

@@ -197,3 +199,2 @@ // ----------

var COMMON_HEADER_SIZE = 8;
var MAX_PAYLOAD_SIZE = 16383;

@@ -215,3 +216,2 @@ var frameTypes = [];

}
assert(size <= MAX_PAYLOAD_SIZE, size);
headerBuffer.writeUInt16BE(size, 0);

@@ -218,0 +218,0 @@

{
"name": "http2-protocol",
"version": "0.9.0",
"version": "0.9.1",
"description": "A JavaScript implementation of the HTTP/2 framing layer",

@@ -18,3 +18,3 @@ "main": "lib/index.js",

"test": "istanbul test _mocha -- --reporter spec --slow 200",
"prepublish": "docco lib/* --output doc --layout parallel --css doc/docco.css"
"doc": "docco lib/* --output doc --layout parallel --css doc/docco.css"
},

@@ -21,0 +21,0 @@ "repository": {

@@ -41,5 +41,5 @@ node-http2-protocol

The developer documentation is located in the `doc` directory. The docs are usually updated only
before releasing a new version. To regenerate them manually, run `npm run-script prepublish`.
There's a hosted version which is located [here](http://molnarg.github.io/node-http2-protocol/doc/).
The developer documentation is generated from the source code using docco and can be viewed online
[here](http://molnarg.github.io/node-http2-protocol/doc/). If you'd like to have an offline copy,
just run `npm run-script doc`.

@@ -54,3 +54,3 @@ ### Running the tests ###

To generate a code coverage report, run `npm test --coverage` (it may be slow, be patient).
Code coverage summary as of version 0.6.0:
Code coverage summary as of version 0.9.0:
```

@@ -57,0 +57,0 @@ Statements : 92.43% ( 1257/1360 )

@@ -23,3 +23,3 @@ var path = require('path');

level: process.env.HTTP2_LOG,
serializers: require('../lib/http').serializers
serializers: require('..').serializers
});

@@ -26,0 +26,0 @@ };

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