From 04eaa9fc621635580d4feccb9c4e2288a00f602d Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Mon, 11 May 2015 14:40:39 +0200 Subject: [PATCH 01/33] added .opml file as text fixture --- test/content-type.js | 19 +++++++++++++++++++ test/public/custom_mime_type.opml | 13 +++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 test/public/custom_mime_type.opml diff --git a/test/content-type.js b/test/content-type.js index 4340aef..5424f49 100644 --- a/test/content-type.js +++ b/test/content-type.js @@ -24,3 +24,22 @@ test('default default contentType', function(t) { }); }); +test('custom contentType', function(t) { + var server = http.createServer(ecstatic({ + root: __dirname + '/public/' + })); + + t.plan(3); + + t.on('end', function() { server.close(); }); + + server.listen(0, function() { + var port = server.address().port; + request.get('http://localhost:' + port + '/custom_mime_type.opml', function(err, res, body) { + t.ifError(err); + t.equal(res.statusCode, 200); + t.equal(res.headers['content-type'], 'application/xml; charset=UTF-8'); + t.end(); + }); + }); +}); \ No newline at end of file diff --git a/test/public/custom_mime_type.opml b/test/public/custom_mime_type.opml new file mode 100644 index 0000000..53f3582 --- /dev/null +++ b/test/public/custom_mime_type.opml @@ -0,0 +1,13 @@ + + + + + Tue 9 May 2006 06:44:27 GMT+00:00 + BKN + Sat 20 May 2006 00:17:25 GMT+00:00 + + + + + + From e22dc921ff2a90f30c7c923122c09584df311049 Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Mon, 11 May 2015 16:26:31 +0200 Subject: [PATCH 02/33] test mime package --- test/mime.js | 47 ++++++++++++++++++++++++++++++ test/public/custom_mime_type.types | 4 +++ 2 files changed, 51 insertions(+) create mode 100644 test/mime.js create mode 100644 test/public/custom_mime_type.types diff --git a/test/mime.js b/test/mime.js new file mode 100644 index 0000000..54629a1 --- /dev/null +++ b/test/mime.js @@ -0,0 +1,47 @@ +var test = require('tap').test, + mime; + +function setup() { + mime = require('mime'); +} +function teardown(t) { + t && t.end(); + mime = null; +} + +test('mime package lookup', function(t) { + setup(); + + t.plan(4); + + t.equal(mime.lookup('/path/to/file.txt'), 'text/plain'); + t.equal(mime.lookup('file.txt'), 'text/plain'); + t.equal(mime.lookup('.TXT'), 'text/plain'); + t.equal(mime.lookup('htm'), 'text/html'); + + teardown(t); +}); + +test('custom definition of mime-type with the mime package', function(t) { + setup(); + + t.plan(1); + + mime.define({ + 'application/xml': ['opml'] + }); + t.equal(mime.lookup('.opml'), 'application/xml'); + + teardown(t); +}); + +test('custom definition of mime-type with a .types file', function(t) { + setup(); + + t.plan(1); + + mime.load('public/custom_mime_type.types'); + t.equal(mime.lookup('.opml'), 'application/xml'); + + teardown(t); +}); \ No newline at end of file diff --git a/test/public/custom_mime_type.types b/test/public/custom_mime_type.types new file mode 100644 index 0000000..f8d4292 --- /dev/null +++ b/test/public/custom_mime_type.types @@ -0,0 +1,4 @@ +# This file is an example of the Apache .types file format +# for descriping mime-types. +# Other example: https://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x/conf/mime.types +application/xml opml \ No newline at end of file From 285215b36abc6c4bed185eaceaf30b217dfc9205 Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Mon, 11 May 2015 17:43:02 +0200 Subject: [PATCH 03/33] test custom mime type(s) via mime --- lib/ecstatic.js | 16 ++- lib/ecstatic/opts.js | 257 +++++++++++++++++++++++-------------------- test/content-type.js | 29 ++++- test/mime.js | 26 +++-- 4 files changed, 196 insertions(+), 132 deletions(-) diff --git a/lib/ecstatic.js b/lib/ecstatic.js index b17afd5..9778dd9 100755 --- a/lib/ecstatic.js +++ b/lib/ecstatic.js @@ -31,6 +31,20 @@ var ecstatic = module.exports = function (dir, options) { opts.root = dir; if (defaultExt && /^\./.test(defaultExt)) defaultExt = defaultExt.replace(/^\./, ''); + // Support hashes and .types files in mimeTypes @since 0.8 + if (opts.mimeTypes) { + if (opts.mimeTypes instanceof String) { + try { + mime.load(opts.mimeTypes); + } catch(e) { + console.debug(e.message); + } + } else if (typeof opts.mimeTypes === 'object') { + mime.define(opts.mimeTypes); + } + } + + return function middleware (req, res, next) { // Strip any null bytes from the url @@ -188,7 +202,7 @@ var ecstatic = module.exports = function (dir, options) { status['500'](res, next, { error: err }); }); res.on('close', function () { - fstream.destroy(); + fstream.destroy(); }); res.writeHead(206, { 'Content-Range': 'bytes ' + start + '-' + end + '/' + total, diff --git a/lib/ecstatic/opts.js b/lib/ecstatic/opts.js index 421e623..970109e 100644 --- a/lib/ecstatic/opts.js +++ b/lib/ecstatic/opts.js @@ -2,121 +2,144 @@ module.exports = function (opts) { - var autoIndex = true, - showDir = true, - humanReadable = true, - si = false, - cache = 'max-age=3600', - gzip = false, - defaultExt = '.html', - handleError = true, - serverHeader = true; - contentType = 'application/octet-stream'; - - if (opts) { - [ - 'autoIndex', - 'autoindex' - ].some(function (k) { - if (typeof opts[k] !== 'undefined' && opts[k] !== null) { - autoIndex = opts[k]; - return true; - } - }); - - [ - 'showDir', - 'showdir' - ].some(function (k) { - if (typeof opts[k] !== 'undefined' && opts[k] !== null) { - showDir = opts[k]; - return true; - } - }); - - [ - 'humanReadable', - 'humanreadable', - 'human-readable' - ].some(function (k) { - if (typeof opts[k] !== 'undefined' && opts[k] !== null) { - humanReadable = opts[k]; - return true; - } - }); - - [ - 'si', - 'index' - ].some(function (k) { - if (typeof opts[k] !== 'undefined' && opts[k] !== null) { - si = opts[k]; - return true; - } - }); - - if (opts.defaultExt && typeof opts.defaultExt === 'string') { - defaultExt = opts.defaultExt; - } - - if (typeof opts.cache !== 'undefined' && opts.cache !== null) { - if (typeof opts.cache === 'string') { - cache = opts.cache; - } - else if(typeof opts.cache === 'number') { - cache = 'max-age=' + opts.cache; - } - } - - if (typeof opts.gzip !== 'undefined' && opts.gzip !== null) { - gzip = opts.gzip; - } - - [ - 'handleError', - 'handleerror' - ].some(function (k) { - if (typeof opts[k] !== 'undefined' && opts[k] !== null) { - handleError = opts[k]; - return true; - } - }); - - [ - 'serverHeader', - 'serverheader', - 'server-header' - ].some(function (k) { - if (typeof opts[k] !== 'undefined' && opts[k] !== null) { - serverHeader = opts[k]; - return true; - } - }); - - [ - 'contentType', - 'contenttype', - 'content-type' - ].some(function (k) { - if (typeof opts[k] !== 'undefined' && opts[k] !== null) { - contentType = opts[k]; - return true; - } - }); - - } - - return { - cache: cache, - autoIndex: autoIndex, - showDir: showDir, - humanReadable: humanReadable, - si: si, - defaultExt: defaultExt, - baseDir: (opts && opts.baseDir) || '/', - gzip: gzip, - handleError: handleError, - serverHeader: serverHeader, - contentType: contentType - }; + var autoIndex = true, + showDir = true, + humanReadable = true, + si = false, + cache = 'max-age=3600', + gzip = false, + defaultExt = '.html', + handleError = true, + serverHeader = true, + contentType = 'application/octet-stream', + mimeTypes; + + function isDeclared(k) { + return typeof opts[k] !== 'undefined' && opts[k] !== null; + } + + if (opts) { + [ + 'autoIndex', + 'autoindex' + ].some(function (k) { + if (isDeclared(k)) { + autoIndex = opts[k]; + return true; + } + }); + + [ + 'showDir', + 'showdir' + ].some(function (k) { + if (isDeclared(k)) { + showDir = opts[k]; + return true; + } + }); + + [ + 'humanReadable', + 'humanreadable', + 'human-readable' + ].some(function (k) { + if (isDeclared(k)) { + humanReadable = opts[k]; + return true; + } + }); + + [ + 'si', + 'index' + ].some(function (k) { + if (isDeclared(k)) { + si = opts[k]; + return true; + } + }); + + if (opts.defaultExt && typeof opts.defaultExt === 'string') { + defaultExt = opts.defaultExt; + } + + if (typeof opts.cache !== 'undefined' && opts.cache !== null) { + if (typeof opts.cache === 'string') { + cache = opts.cache; + } + else if(typeof opts.cache === 'number') { + cache = 'max-age=' + opts.cache; + } + } + + if (typeof opts.gzip !== 'undefined' && opts.gzip !== null) { + gzip = opts.gzip; + } + + [ + 'handleError', + 'handleerror' + ].some(function (k) { + if (isDeclared(k)) { + handleError = opts[k]; + return true; + } + }); + + [ + 'serverHeader', + 'serverheader', + 'server-header' + ].some(function (k) { + if (isDeclared(k)) { + serverHeader = opts[k]; + return true; + } + }); + + [ + 'contentType', + 'contenttype', + 'content-type' + ].some(function (k) { + if (isDeclared(k)) { + contentType = opts[k]; + return true; + } + }); + + [ + 'mimetype', + 'mimetypes', + 'mimeType', + 'mimeTypes', + 'mime-type', + 'mime-types', + 'mime-Type', + 'mime-Types' + ].some(function (k) { + k = k.toLowerCase(); + if (isDeclared(k)) { + mimeTypes = opts[k]; + return true; + } + }); + + } + + return { + cache: cache, + autoIndex: autoIndex, + showDir: showDir, + humanReadable: humanReadable, + si: si, + defaultExt: defaultExt, + baseDir: (opts && opts.baseDir) || '/', + gzip: gzip, + handleError: handleError, + serverHeader: serverHeader, + contentType: contentType, + mimeTypes: mimeTypes + }; }; diff --git a/test/content-type.js b/test/content-type.js index 5424f49..b2c000d 100644 --- a/test/content-type.js +++ b/test/content-type.js @@ -1,3 +1,4 @@ +/// var test = require('tap').test, ecstatic = require('../'), http = require('http'), @@ -26,7 +27,31 @@ test('default default contentType', function(t) { test('custom contentType', function(t) { var server = http.createServer(ecstatic({ - root: __dirname + '/public/' + root: __dirname + '/public/', + mimetype: { + 'application/xml': ['opml'] + } + })); + + t.plan(3); + + t.on('end', function() { server.close(); }); + + server.listen(0, function() { + var port = server.address().port; + request.get('http://localhost:' + port + '/custom_mime_type.opml', function(err, res, body) { + t.ifError(err); + t.equal(res.statusCode, 200); + t.equal(res.headers['content-type'], 'application/xml; charset=utf-8'); + t.end(); + }); + }); +}); + +test('custom contentType', function(t) { + var server = http.createServer(ecstatic({ + root: __dirname + '/public/', + 'mime-types': 'custom_mime_type.types' })); t.plan(3); @@ -38,7 +63,7 @@ test('custom contentType', function(t) { request.get('http://localhost:' + port + '/custom_mime_type.opml', function(err, res, body) { t.ifError(err); t.equal(res.statusCode, 200); - t.equal(res.headers['content-type'], 'application/xml; charset=UTF-8'); + t.equal(res.headers['content-type'], 'application/xml; charset=utf-8'); t.end(); }); }); diff --git a/test/mime.js b/test/mime.js index 54629a1..9fa52df 100644 --- a/test/mime.js +++ b/test/mime.js @@ -1,6 +1,6 @@ var test = require('tap').test, mime; - + function setup() { mime = require('mime'); } @@ -11,37 +11,39 @@ function teardown(t) { test('mime package lookup', function(t) { setup(); - + t.plan(4); - + t.equal(mime.lookup('/path/to/file.txt'), 'text/plain'); t.equal(mime.lookup('file.txt'), 'text/plain'); t.equal(mime.lookup('.TXT'), 'text/plain'); t.equal(mime.lookup('htm'), 'text/html'); - + teardown(t); }); test('custom definition of mime-type with the mime package', function(t) { setup(); - + t.plan(1); - + mime.define({ 'application/xml': ['opml'] }); t.equal(mime.lookup('.opml'), 'application/xml'); - + teardown(t); }); test('custom definition of mime-type with a .types file', function(t) { setup(); - - t.plan(1); - + + t.plan(2); + mime.load('public/custom_mime_type.types'); t.equal(mime.lookup('.opml'), 'application/xml'); - + + t.throws( mime.load.bind(mime, 'public/this_file_does_not_exist.types') ); + teardown(t); -}); \ No newline at end of file +}); From 5966dbbafef8ef36fb8be0fe96d7e0be3c2a2704 Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Mon, 11 May 2015 16:27:12 +0200 Subject: [PATCH 04/33] bumb version to 0.8.0 - new feature 'custom mimetypes' --- ChangeLog.md | 3 + lib/ecstatic/opts.js | 272 ++++++++++++++--------------- package.json | 2 +- test/public/custom_mime_type.types | 2 +- 4 files changed, 141 insertions(+), 138 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index da6a393..33a2306 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,3 +1,6 @@ +2015/05/11 Version 0.8.0 +- Add ability to define custom mime-types, inline or with Apache .types file. + 2015/05/09 Version 0.7.6 - Fix double encoding in directory listings diff --git a/lib/ecstatic/opts.js b/lib/ecstatic/opts.js index 970109e..b9738df 100644 --- a/lib/ecstatic/opts.js +++ b/lib/ecstatic/opts.js @@ -2,144 +2,144 @@ module.exports = function (opts) { - var autoIndex = true, - showDir = true, - humanReadable = true, - si = false, - cache = 'max-age=3600', - gzip = false, - defaultExt = '.html', - handleError = true, - serverHeader = true, - contentType = 'application/octet-stream', + var autoIndex = true, + showDir = true, + humanReadable = true, + si = false, + cache = 'max-age=3600', + gzip = false, + defaultExt = '.html', + handleError = true, + serverHeader = true, + contentType = 'application/octet-stream', mimeTypes; - function isDeclared(k) { - return typeof opts[k] !== 'undefined' && opts[k] !== null; - } - - if (opts) { - [ - 'autoIndex', - 'autoindex' - ].some(function (k) { - if (isDeclared(k)) { - autoIndex = opts[k]; - return true; - } - }); - - [ - 'showDir', - 'showdir' - ].some(function (k) { - if (isDeclared(k)) { - showDir = opts[k]; - return true; - } - }); - - [ - 'humanReadable', - 'humanreadable', - 'human-readable' - ].some(function (k) { - if (isDeclared(k)) { - humanReadable = opts[k]; - return true; - } - }); - - [ - 'si', - 'index' - ].some(function (k) { - if (isDeclared(k)) { - si = opts[k]; - return true; - } - }); - - if (opts.defaultExt && typeof opts.defaultExt === 'string') { - defaultExt = opts.defaultExt; - } - - if (typeof opts.cache !== 'undefined' && opts.cache !== null) { - if (typeof opts.cache === 'string') { - cache = opts.cache; - } - else if(typeof opts.cache === 'number') { - cache = 'max-age=' + opts.cache; - } - } - - if (typeof opts.gzip !== 'undefined' && opts.gzip !== null) { - gzip = opts.gzip; - } - - [ - 'handleError', - 'handleerror' - ].some(function (k) { - if (isDeclared(k)) { - handleError = opts[k]; - return true; - } - }); - - [ - 'serverHeader', - 'serverheader', - 'server-header' - ].some(function (k) { - if (isDeclared(k)) { - serverHeader = opts[k]; - return true; - } - }); - - [ - 'contentType', - 'contenttype', - 'content-type' - ].some(function (k) { - if (isDeclared(k)) { - contentType = opts[k]; - return true; - } - }); - - [ - 'mimetype', - 'mimetypes', - 'mimeType', - 'mimeTypes', - 'mime-type', - 'mime-types', - 'mime-Type', - 'mime-Types' - ].some(function (k) { - k = k.toLowerCase(); - if (isDeclared(k)) { + function isDeclared(k) { + return typeof opts[k] !== 'undefined' && opts[k] !== null; + } + + if (opts) { + [ + 'autoIndex', + 'autoindex' + ].some(function (k) { + if (isDeclared(k)) { + autoIndex = opts[k]; + return true; + } + }); + + [ + 'showDir', + 'showdir' + ].some(function (k) { + if (isDeclared(k)) { + showDir = opts[k]; + return true; + } + }); + + [ + 'humanReadable', + 'humanreadable', + 'human-readable' + ].some(function (k) { + if (isDeclared(k)) { + humanReadable = opts[k]; + return true; + } + }); + + [ + 'si', + 'index' + ].some(function (k) { + if (isDeclared(k)) { + si = opts[k]; + return true; + } + }); + + if (opts.defaultExt && typeof opts.defaultExt === 'string') { + defaultExt = opts.defaultExt; + } + + if (typeof opts.cache !== 'undefined' && opts.cache !== null) { + if (typeof opts.cache === 'string') { + cache = opts.cache; + } + else if(typeof opts.cache === 'number') { + cache = 'max-age=' + opts.cache; + } + } + + if (typeof opts.gzip !== 'undefined' && opts.gzip !== null) { + gzip = opts.gzip; + } + + [ + 'handleError', + 'handleerror' + ].some(function (k) { + if (isDeclared(k)) { + handleError = opts[k]; + return true; + } + }); + + [ + 'serverHeader', + 'serverheader', + 'server-header' + ].some(function (k) { + if (isDeclared(k)) { + serverHeader = opts[k]; + return true; + } + }); + + [ + 'contentType', + 'contenttype', + 'content-type' + ].some(function (k) { + if (isDeclared(k)) { + contentType = opts[k]; + return true; + } + }); + + [ + 'mimetype', + 'mimetypes', + 'mimeType', + 'mimeTypes', + 'mime-type', + 'mime-types', + 'mime-Type', + 'mime-Types' + ].some(function (k) { + k = k.toLowerCase(); + if (isDeclared(k)) { mimeTypes = opts[k]; - return true; - } - }); - - } - - return { - cache: cache, - autoIndex: autoIndex, - showDir: showDir, - humanReadable: humanReadable, - si: si, - defaultExt: defaultExt, - baseDir: (opts && opts.baseDir) || '/', - gzip: gzip, - handleError: handleError, - serverHeader: serverHeader, - contentType: contentType, + return true; + } + }); + + } + + return { + cache: cache, + autoIndex: autoIndex, + showDir: showDir, + humanReadable: humanReadable, + si: si, + defaultExt: defaultExt, + baseDir: (opts && opts.baseDir) || '/', + gzip: gzip, + handleError: handleError, + serverHeader: serverHeader, + contentType: contentType, mimeTypes: mimeTypes - }; + }; }; diff --git a/package.json b/package.json index 81b8732..0003839 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Joshua Holbrook (http://jesusabdullah.net)", "name": "ecstatic", "description": "A simple static file server middleware that works with both Express and Flatiron", - "version": "0.7.6", + "version": "0.8.0", "homepage": "https://github.com/jfhbrook/node-ecstatic", "repository": { "type": "git", diff --git a/test/public/custom_mime_type.types b/test/public/custom_mime_type.types index f8d4292..a1f6998 100644 --- a/test/public/custom_mime_type.types +++ b/test/public/custom_mime_type.types @@ -1,4 +1,4 @@ # This file is an example of the Apache .types file format # for descriping mime-types. # Other example: https://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x/conf/mime.types -application/xml opml \ No newline at end of file +application/xml opml From 140872fecd3a9c339766221214141fcc7872d7fc Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Mon, 11 May 2015 18:13:32 +0200 Subject: [PATCH 05/33] tried to test what happens if a wrong path is given to .types file but did not work --- lib/ecstatic.js | 2 +- test/content-type.js | 58 ++++++++++++++++++++++++++++++++++---------- 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/lib/ecstatic.js b/lib/ecstatic.js index 9778dd9..62337cc 100755 --- a/lib/ecstatic.js +++ b/lib/ecstatic.js @@ -36,7 +36,7 @@ var ecstatic = module.exports = function (dir, options) { if (opts.mimeTypes instanceof String) { try { mime.load(opts.mimeTypes); - } catch(e) { + } catch(e) { /* NOT SURE HOW TO TEST THIS - SEE COMMENT IN PR */ console.debug(e.message); } } else if (typeof opts.mimeTypes === 'object') { diff --git a/test/content-type.js b/test/content-type.js index b2c000d..46b85a4 100644 --- a/test/content-type.js +++ b/test/content-type.js @@ -1,14 +1,23 @@ /// var test = require('tap').test, - ecstatic = require('../'), http = require('http'), - request = require('request'); + request = require('request'), + ecstatic; + +function setup(opts) { + ecstatic = require('../'); + return http.createServer(ecstatic(opts)); +} +function teardown(t) { + t && t.end(); + ecstatic = null; +} test('default default contentType', function(t) { - var server = http.createServer(ecstatic({ + var server = setup({ root: __dirname + '/public/', contentType: 'text/plain' - })); + }); t.plan(3); @@ -20,18 +29,18 @@ test('default default contentType', function(t) { t.ifError(err); t.equal(res.statusCode, 200); t.equal(res.headers['content-type'], 'text/plain; charset=UTF-8'); - t.end(); + teardown(t); }); }); }); test('custom contentType', function(t) { - var server = http.createServer(ecstatic({ + var server = setup({ root: __dirname + '/public/', mimetype: { 'application/xml': ['opml'] } - })); + }); t.plan(3); @@ -43,16 +52,16 @@ test('custom contentType', function(t) { t.ifError(err); t.equal(res.statusCode, 200); t.equal(res.headers['content-type'], 'application/xml; charset=utf-8'); - t.end(); + teardown(); }); }); }); -test('custom contentType', function(t) { - var server = http.createServer(ecstatic({ +test('custom contentType via .types file', function(t) { + var server = setup({ root: __dirname + '/public/', 'mime-types': 'custom_mime_type.types' - })); + }); t.plan(3); @@ -64,7 +73,30 @@ test('custom contentType', function(t) { t.ifError(err); t.equal(res.statusCode, 200); t.equal(res.headers['content-type'], 'application/xml; charset=utf-8'); - t.end(); + teardown(); }); }); -}); \ No newline at end of file +}); + +/* NOT SURE HOW TO TEST THIS - SEE COMMENT IN PR +test('warning when custom contentType .types file does not exist', function(t) { + var server = setup({ + root: __dirname + '/public/', + 'mime-types': 'this_file_does_not_exist.types' + }); + + t.plan(3); + + t.on('end', function() { server.close(); }); + + server.listen(0, function() { + var port = server.address().port; + request.get('http://localhost:' + port + '/custom_mime_type.opml', function(err, res, body) { + t.ifError(err); + t.equal(res.statusCode, 200); + t.equal(res.headers['content-type'], 'application/xml; charset=utf-8'); + teardown(); + }); + }); +}); +*/ From 81d18206911e6c90bb6c8ca0d3841fa13c0a2736 Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Mon, 11 May 2015 19:22:43 +0200 Subject: [PATCH 06/33] documentation --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1a8057c..7f4b253 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,9 @@ var opts = { si : false, defaultExt : 'html', gzip : false, - serverHeader : true + serverHeader : true, + contentType : 'application/octet-stream', + mimeTypes : undefined } ``` @@ -139,6 +141,13 @@ on all responses served by ecstatic. Set `opts.contentType` in order to change default Content-Type header value. Defaults to **application/octet-stream**. +### `opts.mimeTypes` + +Add new or override one or more mime-types. This affects the HTTP Content-Type header. +Can either be a path to a [`.types`](https://www.sympa.org/distribution/sympa-6.2b.9/default/mime.types) file or an object hash of type(s). + + ecstatic({ mimeType: { 'mime-type': ['file_extension', 'file_extension'] } }) + ### `opts.handleError` Turn **off** handleErrors to allow fall-through with `opts.handleError === false`, Defaults to **true**. From 3a13400cb9a1e55611dc01557bb61ab8a3f228c9 Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Tue, 12 May 2015 00:22:23 +0200 Subject: [PATCH 07/33] fixed loading of .types file and test that ecstatic throws if path to .types file is wrong --- lib/ecstatic.js | 8 ++------ test/content-type.js | 32 +++++++++++--------------------- 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/lib/ecstatic.js b/lib/ecstatic.js index 62337cc..ffd797a 100755 --- a/lib/ecstatic.js +++ b/lib/ecstatic.js @@ -33,12 +33,8 @@ var ecstatic = module.exports = function (dir, options) { // Support hashes and .types files in mimeTypes @since 0.8 if (opts.mimeTypes) { - if (opts.mimeTypes instanceof String) { - try { - mime.load(opts.mimeTypes); - } catch(e) { /* NOT SURE HOW TO TEST THIS - SEE COMMENT IN PR */ - console.debug(e.message); - } + if (typeof opts.mimeTypes === 'string') { + mime.load( path.join(dir, opts.mimeTypes) ); } else if (typeof opts.mimeTypes === 'object') { mime.define(opts.mimeTypes); } diff --git a/test/content-type.js b/test/content-type.js index 46b85a4..ea7af6c 100644 --- a/test/content-type.js +++ b/test/content-type.js @@ -52,7 +52,7 @@ test('custom contentType', function(t) { t.ifError(err); t.equal(res.statusCode, 200); t.equal(res.headers['content-type'], 'application/xml; charset=utf-8'); - teardown(); + teardown(t); }); }); }); @@ -73,30 +73,20 @@ test('custom contentType via .types file', function(t) { t.ifError(err); t.equal(res.statusCode, 200); t.equal(res.headers['content-type'], 'application/xml; charset=utf-8'); - teardown(); + teardown(t); }); }); }); -/* NOT SURE HOW TO TEST THIS - SEE COMMENT IN PR -test('warning when custom contentType .types file does not exist', function(t) { - var server = setup({ - root: __dirname + '/public/', - 'mime-types': 'this_file_does_not_exist.types' - }); - - t.plan(3); +test('throws when custom contentType .types file does not exist', function(t) { + t.plan(1); - t.on('end', function() { server.close(); }); + t.throws( + setup.bind(null, { + root: __dirname + '/public/', + 'mime-types': 'this_file_does_not_exist.types' + }) + ); - server.listen(0, function() { - var port = server.address().port; - request.get('http://localhost:' + port + '/custom_mime_type.opml', function(err, res, body) { - t.ifError(err); - t.equal(res.statusCode, 200); - t.equal(res.headers['content-type'], 'application/xml; charset=utf-8'); - teardown(); - }); - }); + teardown(t); }); -*/ From 303ea14970f03aaa15a992c89dca681738832702 Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Tue, 12 May 2015 00:33:52 +0200 Subject: [PATCH 08/33] fix alias for mime-type being wrongly lowercased before comparison --- lib/ecstatic/opts.js | 1 - test/content-type.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/ecstatic/opts.js b/lib/ecstatic/opts.js index b9738df..77d78a8 100644 --- a/lib/ecstatic/opts.js +++ b/lib/ecstatic/opts.js @@ -119,7 +119,6 @@ module.exports = function (opts) { 'mime-Type', 'mime-Types' ].some(function (k) { - k = k.toLowerCase(); if (isDeclared(k)) { mimeTypes = opts[k]; return true; diff --git a/test/content-type.js b/test/content-type.js index ea7af6c..4dafc89 100644 --- a/test/content-type.js +++ b/test/content-type.js @@ -84,7 +84,7 @@ test('throws when custom contentType .types file does not exist', function(t) { t.throws( setup.bind(null, { root: __dirname + '/public/', - 'mime-types': 'this_file_does_not_exist.types' + mimeTypes: 'this_file_does_not_exist.types' }) ); From 0db475f5a3ce453c2c29950d6e50d0a1ce0be437 Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Tue, 12 May 2015 02:52:16 +0200 Subject: [PATCH 09/33] remove teardown function as it does not work --- test/content-type.js | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/test/content-type.js b/test/content-type.js index 4dafc89..beed56f 100644 --- a/test/content-type.js +++ b/test/content-type.js @@ -1,17 +1,11 @@ -/// var test = require('tap').test, http = require('http'), request = require('request'), - ecstatic; + ecstatic = require('../'); function setup(opts) { - ecstatic = require('../'); return http.createServer(ecstatic(opts)); } -function teardown(t) { - t && t.end(); - ecstatic = null; -} test('default default contentType', function(t) { var server = setup({ @@ -29,7 +23,6 @@ test('default default contentType', function(t) { t.ifError(err); t.equal(res.statusCode, 200); t.equal(res.headers['content-type'], 'text/plain; charset=UTF-8'); - teardown(t); }); }); }); @@ -52,7 +45,6 @@ test('custom contentType', function(t) { t.ifError(err); t.equal(res.statusCode, 200); t.equal(res.headers['content-type'], 'application/xml; charset=utf-8'); - teardown(t); }); }); }); @@ -73,7 +65,6 @@ test('custom contentType via .types file', function(t) { t.ifError(err); t.equal(res.statusCode, 200); t.equal(res.headers['content-type'], 'application/xml; charset=utf-8'); - teardown(t); }); }); }); @@ -88,5 +79,4 @@ test('throws when custom contentType .types file does not exist', function(t) { }) ); - teardown(t); }); From 71b4fa6e2c58b1d2e270a9562558306aaef343a2 Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Tue, 12 May 2015 12:59:25 +0200 Subject: [PATCH 10/33] unit test for the new feature 'custom mime-types' - with the ultimate teardown - it kills the process --- README.md | 2 +- test/content-type.js | 65 +++++------------------------- test/custom-content-type-file.js | 47 +++++++++++++++++++++ test/custom-content-type.js | 37 +++++++++++++++++ test/public/custom_mime_type.types | 2 +- 5 files changed, 95 insertions(+), 58 deletions(-) create mode 100644 test/custom-content-type-file.js create mode 100644 test/custom-content-type.js diff --git a/README.md b/README.md index 7f4b253..3dfc874 100644 --- a/README.md +++ b/README.md @@ -144,7 +144,7 @@ Defaults to **application/octet-stream**. ### `opts.mimeTypes` Add new or override one or more mime-types. This affects the HTTP Content-Type header. -Can either be a path to a [`.types`](https://www.sympa.org/distribution/sympa-6.2b.9/default/mime.types) file or an object hash of type(s). +Can either be a path to a [`.types`](http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types) file or an object hash of type(s). ecstatic({ mimeType: { 'mime-type': ['file_extension', 'file_extension'] } }) diff --git a/test/content-type.js b/test/content-type.js index beed56f..4f9e723 100644 --- a/test/content-type.js +++ b/test/content-type.js @@ -6,6 +6,14 @@ var test = require('tap').test, function setup(opts) { return http.createServer(ecstatic(opts)); } +function teardown(opts) { + opts = opts || {}; + opts.server.close(function() { + opts.t && opts.t.end(); + process.stderr.write('# server not closing; slaughtering process.\n'); + process.exit(0); + }); +} test('default default contentType', function(t) { var server = setup({ @@ -15,68 +23,13 @@ test('default default contentType', function(t) { t.plan(3); - t.on('end', function() { server.close(); }); - server.listen(0, function() { var port = server.address().port; request.get('http://localhost:' + port + '/f_f', function(err, res, body) { t.ifError(err); t.equal(res.statusCode, 200); t.equal(res.headers['content-type'], 'text/plain; charset=UTF-8'); + teardown({ t:t, server:server }); }); }); }); - -test('custom contentType', function(t) { - var server = setup({ - root: __dirname + '/public/', - mimetype: { - 'application/xml': ['opml'] - } - }); - - t.plan(3); - - t.on('end', function() { server.close(); }); - - server.listen(0, function() { - var port = server.address().port; - request.get('http://localhost:' + port + '/custom_mime_type.opml', function(err, res, body) { - t.ifError(err); - t.equal(res.statusCode, 200); - t.equal(res.headers['content-type'], 'application/xml; charset=utf-8'); - }); - }); -}); - -test('custom contentType via .types file', function(t) { - var server = setup({ - root: __dirname + '/public/', - 'mime-types': 'custom_mime_type.types' - }); - - t.plan(3); - - t.on('end', function() { server.close(); }); - - server.listen(0, function() { - var port = server.address().port; - request.get('http://localhost:' + port + '/custom_mime_type.opml', function(err, res, body) { - t.ifError(err); - t.equal(res.statusCode, 200); - t.equal(res.headers['content-type'], 'application/xml; charset=utf-8'); - }); - }); -}); - -test('throws when custom contentType .types file does not exist', function(t) { - t.plan(1); - - t.throws( - setup.bind(null, { - root: __dirname + '/public/', - mimeTypes: 'this_file_does_not_exist.types' - }) - ); - -}); diff --git a/test/custom-content-type-file.js b/test/custom-content-type-file.js new file mode 100644 index 0000000..e63f05c --- /dev/null +++ b/test/custom-content-type-file.js @@ -0,0 +1,47 @@ +var test = require('tap').test, + http = require('http'), + request = require('request'), + ecstatic = require('../'); + +function setup(opts) { + return http.createServer(ecstatic(opts)); +} +function teardown(opts) { + opts = opts || {}; + opts.server.close(function() { + opts.t && opts.t.end(); + process.stderr.write('# server not closing; slaughtering process.\n'); + process.exit(0); + }); +} + +test('custom contentType via .types file', function(t) { + var server = setup({ + root: __dirname + '/public/', + 'mime-types': 'custom_mime_type.types' + }); + + t.plan(3) + + server.listen(0, function() { + var port = server.address().port; + request.get('http://localhost:' + port + '/custom_mime_type.opml', function(err, res, body) { + t.ifError(err); + t.equal(res.statusCode, 200); + t.equal(res.headers['content-type'], 'application/foo; charset=utf-8'); + teardown({ t:t, server:server }); + }); + }); +}); + +test('throws when custom contentType .types file does not exist', function(t) { + t.plan(1); + + t.throws( + setup.bind(null, { + root: __dirname + '/public/', + mimeTypes: 'this_file_does_not_exist.types' + }) + ); + +}); diff --git a/test/custom-content-type.js b/test/custom-content-type.js new file mode 100644 index 0000000..16e2ecb --- /dev/null +++ b/test/custom-content-type.js @@ -0,0 +1,37 @@ +var test = require('tap').test, + http = require('http'), + request = require('request'), + ecstatic = require('../'); + +function setup(opts) { + return http.createServer(ecstatic(opts)); +} +function teardown(opts) { + opts = opts || {}; + opts.server.close(function() { + opts.t && opts.t.end(); + process.stderr.write('# server not closing; slaughtering process.\n'); + process.exit(0); + }); +} + +test('custom contentType', function(t) { + var server = setup({ + root: __dirname + '/public/', + mimetype: { + 'application/jon': ['opml'] + } + }); + + t.plan(3); + + server.listen(0, function() { + var port = server.address().port; + request.get('http://localhost:' + port + '/custom_mime_type.opml', function(err, res, body) { + t.ifError(err); + t.equal(res.statusCode, 200); + t.equal(res.headers['content-type'], 'application/jon; charset=utf-8'); + teardown({ t:t, server:server }); + }); + }); +}); diff --git a/test/public/custom_mime_type.types b/test/public/custom_mime_type.types index a1f6998..6220c2a 100644 --- a/test/public/custom_mime_type.types +++ b/test/public/custom_mime_type.types @@ -1,4 +1,4 @@ # This file is an example of the Apache .types file format # for descriping mime-types. # Other example: https://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x/conf/mime.types -application/xml opml +application/foo opml From 1d5de3e0d33296f9088bfaee554b6a681a0d59ba Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Tue, 12 May 2015 13:13:54 +0200 Subject: [PATCH 11/33] fixed change in .types has to be reflected in unit test --- test/mime.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mime.js b/test/mime.js index 9fa52df..239b5ce 100644 --- a/test/mime.js +++ b/test/mime.js @@ -41,7 +41,7 @@ test('custom definition of mime-type with a .types file', function(t) { t.plan(2); mime.load('public/custom_mime_type.types'); - t.equal(mime.lookup('.opml'), 'application/xml'); + t.equal(mime.lookup('.opml'), 'application/foo'); // see public/custom_mime_type.types t.throws( mime.load.bind(mime, 'public/this_file_does_not_exist.types') ); From 1462c9043ab8152fb48a965667086998503b2f71 Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Tue, 12 May 2015 17:07:05 +0200 Subject: [PATCH 12/33] added unit test that fails - .types file location should be independent of root directory --- test/public/custom_mime_type.types | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/public/custom_mime_type.types b/test/public/custom_mime_type.types index 6220c2a..1af14d2 100644 --- a/test/public/custom_mime_type.types +++ b/test/public/custom_mime_type.types @@ -1,4 +1,3 @@ -# This file is an example of the Apache .types file format -# for descriping mime-types. -# Other example: https://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x/conf/mime.types +# This file is an example of the Apache .types file format for describing mime-types. +# Other example: http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types application/foo opml From 84ec0b5244fb2ec9f074d866482bfa29377c60a6 Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Tue, 12 May 2015 17:10:00 +0200 Subject: [PATCH 13/33] better do this in a point release as I'm importing ecstatic in http-server --- ChangeLog.md | 3 +++ package.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index 33a2306..317910e 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,3 +1,6 @@ +2015/05/12 Version 0.8.1 +- Fixed an issue where .types file is in another directory that the root directory. + 2015/05/11 Version 0.8.0 - Add ability to define custom mime-types, inline or with Apache .types file. diff --git a/package.json b/package.json index 0003839..8f199ec 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Joshua Holbrook (http://jesusabdullah.net)", "name": "ecstatic", "description": "A simple static file server middleware that works with both Express and Flatiron", - "version": "0.8.0", + "version": "0.8.1", "homepage": "https://github.com/jfhbrook/node-ecstatic", "repository": { "type": "git", From 80d315d21ccd73f8231de13c92d54fe97f4005e9 Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Tue, 12 May 2015 17:30:17 +0200 Subject: [PATCH 14/33] implementation and tests for reading the .types file from an arbitrary location + make __dirname/public/ the default for root --- lib/ecstatic.js | 4 +-- test/custom-content-type-file-secret.js | 35 +++++++++++++++++++++++++ test/custom-content-type-file.js | 3 +-- test/secret/custom_mime_type.types | 3 +++ 4 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 test/custom-content-type-file-secret.js create mode 100644 test/secret/custom_mime_type.types diff --git a/lib/ecstatic.js b/lib/ecstatic.js index ffd797a..9c5c0be 100755 --- a/lib/ecstatic.js +++ b/lib/ecstatic.js @@ -19,7 +19,7 @@ var ecstatic = module.exports = function (dir, options) { dir = options.root; } - var root = path.join(path.resolve(dir), '/'), + var root = dir && path.join(path.resolve(dir), '/') || path.resolve(__dirname + 'public'), opts = optsParser(options), cache = opts.cache, autoIndex = opts.autoIndex, @@ -34,7 +34,7 @@ var ecstatic = module.exports = function (dir, options) { // Support hashes and .types files in mimeTypes @since 0.8 if (opts.mimeTypes) { if (typeof opts.mimeTypes === 'string') { - mime.load( path.join(dir, opts.mimeTypes) ); + mime.load(opts.mimeTypes); // will throw if path is wrong as intended } else if (typeof opts.mimeTypes === 'object') { mime.define(opts.mimeTypes); } diff --git a/test/custom-content-type-file-secret.js b/test/custom-content-type-file-secret.js new file mode 100644 index 0000000..b87d7ed --- /dev/null +++ b/test/custom-content-type-file-secret.js @@ -0,0 +1,35 @@ +var test = require('tap').test, + http = require('http'), + request = require('request'), + ecstatic = require('../'); + +function setup(opts) { + return http.createServer(ecstatic(opts)); +} +function teardown(opts) { + opts = opts || {}; + opts.server.close(function() { + opts.t && opts.t.end(); + process.stderr.write('# server not closing; slaughtering process.\n'); + process.exit(0); + }); +} + +test('custom contentType via .types file', function(t) { + var server = setup({ + root: __dirname + '/public/', + 'mime-types': 'secret/custom_mime_type.types' + }); + + t.plan(3) + + server.listen(0, function() { + var port = server.address().port; + request.get('http://localhost:' + port + '/custom_mime_type.opml', function(err, res, body) { + t.ifError(err); + t.equal(res.statusCode, 200); + t.equal(res.headers['content-type'], 'application/secret; charset=utf-8'); + teardown({ t:t, server:server }); + }); + }); +}); diff --git a/test/custom-content-type-file.js b/test/custom-content-type-file.js index e63f05c..472cd95 100644 --- a/test/custom-content-type-file.js +++ b/test/custom-content-type-file.js @@ -17,8 +17,7 @@ function teardown(opts) { test('custom contentType via .types file', function(t) { var server = setup({ - root: __dirname + '/public/', - 'mime-types': 'custom_mime_type.types' + 'mime-types': 'public/custom_mime_type.types' }); t.plan(3) diff --git a/test/secret/custom_mime_type.types b/test/secret/custom_mime_type.types new file mode 100644 index 0000000..8f68da3 --- /dev/null +++ b/test/secret/custom_mime_type.types @@ -0,0 +1,3 @@ +# This file is an example of the Apache .types file format for describing mime-types. +# Other example: http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types +application/secret opml From 813ea25e4abb9232cdea2632a3c35c4c5f2e9f3f Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Tue, 12 May 2015 19:15:51 +0200 Subject: [PATCH 15/33] updated dependencies --- README.md | 2 +- package.json | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3dfc874..2877c44 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Ecstatic [![build status](https://secure.travis-ci.org/jfhbrook/node-ecstatic.png)](http://travis-ci.org/jfhbrook/node-ecstatic) +# Ecstatic [![build status](https://secure.travis-ci.org/jfhbrook/node-ecstatic.png)](http://travis-ci.org/jfhbrook/node-ecstatic) [![dependencies status](https://david-dm.org/jfhbrook/node-ecstatic.svg)](https://david-dm.org/jfhbrook/node-ecstatic) ![](http://imgur.com/vhub5.png) diff --git a/package.json b/package.json index 8f199ec..6d0d077 100644 --- a/package.json +++ b/package.json @@ -28,10 +28,11 @@ "url-join": "0.0.1" }, "devDependencies": { - "tap": "^0.4.13", + "eol": "^0.2.0", + "express": "^4.12.3", + "mkdirp": "^0.5.0", "request": "^2.49.0", - "express": "^3.0.6", - "union": "^0.3.8", - "mkdirp": "^0.5.0" + "tap": "^1.0.2", + "union": "^0.4.4" } } From 65da86dadaee4902710ae98205401327643cf140 Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Tue, 12 May 2015 20:43:58 +0200 Subject: [PATCH 16/33] remove default root path - it's confusing --- lib/ecstatic.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ecstatic.js b/lib/ecstatic.js index 9c5c0be..b494546 100755 --- a/lib/ecstatic.js +++ b/lib/ecstatic.js @@ -19,7 +19,7 @@ var ecstatic = module.exports = function (dir, options) { dir = options.root; } - var root = dir && path.join(path.resolve(dir), '/') || path.resolve(__dirname + 'public'), + var root = dir && path.join(path.resolve(dir), '/'), opts = optsParser(options), cache = opts.cache, autoIndex = opts.autoIndex, From 126a06ed6a19ad0d0e7a1344f8bf82440b48e980 Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Tue, 12 May 2015 20:44:29 +0200 Subject: [PATCH 17/33] updated tests to run with tap 1.0 and on windows --- test/content-type.js | 27 ++++------ test/core-error.js | 2 +- test/core.js | 9 ++-- test/custom-content-type-file-secret.js | 38 ++++++------- test/custom-content-type-file.js | 54 +++++++++++-------- test/custom-content-type.js | 33 +++++------- test/default-default-ext.js | 7 +-- test/escaping.js | 21 ++------ test/express-error.js | 2 +- test/express.js | 7 +-- test/html-reflection.js | 16 +----- test/malformed-dir.js | 19 ++----- test/malformed.js | 16 +----- test/mime.js | 30 ++++------- test/public/d.js | 2 +- test/range.js | 7 +-- test/{ => secret}/common-cases-error.js | 0 test/{ => secret}/common-cases.js | 4 +- .../union-multiple-folders-cases.js | 0 test/union-error.js | 2 +- test/union-multiple-folders.js | 7 +-- test/union.js | 7 +-- 22 files changed, 128 insertions(+), 182 deletions(-) rename test/{ => secret}/common-cases-error.js (100%) rename test/{ => secret}/common-cases.js (94%) rename test/{ => secret}/union-multiple-folders-cases.js (100%) diff --git a/test/content-type.js b/test/content-type.js index 4f9e723..25c35a4 100644 --- a/test/content-type.js +++ b/test/content-type.js @@ -3,23 +3,16 @@ var test = require('tap').test, request = require('request'), ecstatic = require('../'); -function setup(opts) { - return http.createServer(ecstatic(opts)); -} -function teardown(opts) { - opts = opts || {}; - opts.server.close(function() { - opts.t && opts.t.end(); - process.stderr.write('# server not closing; slaughtering process.\n'); - process.exit(0); - }); -} - test('default default contentType', function(t) { - var server = setup({ - root: __dirname + '/public/', - contentType: 'text/plain' - }); + try { + var server = http.createServer(ecstatic({ + root: __dirname + '/public/', + contentType: 'text/plain' + })); + } catch (e) { + t.fail(e.message); + t.end(); + } t.plan(3); @@ -29,7 +22,7 @@ test('default default contentType', function(t) { t.ifError(err); t.equal(res.statusCode, 200); t.equal(res.headers['content-type'], 'text/plain; charset=UTF-8'); - teardown({ t:t, server:server }); + server.close(function() { t.end(); }); }); }); }); diff --git a/test/core-error.js b/test/core-error.js index d1e769c..80a76dc 100644 --- a/test/core-error.js +++ b/test/core-error.js @@ -11,7 +11,7 @@ var root = __dirname + '/public', mkdirp.sync(root + '/emptyDir'); -var cases = require('./common-cases-error'); +var cases = require('./secret/common-cases-error'); test('core', function (t) { var filenames = Object.keys(cases); diff --git a/test/core.js b/test/core.js index 9e7c716..d5e5e27 100644 --- a/test/core.js +++ b/test/core.js @@ -4,14 +4,15 @@ var test = require('tap').test, request = require('request'), mkdirp = require('mkdirp'), fs = require('fs'), - path = require('path'); + path = require('path'), + eol = require('eol'); var root = __dirname + '/public', baseDir = 'base'; mkdirp.sync(root + '/emptyDir'); -var cases = require('./common-cases'); +var cases = require('./secret/common-cases'); test('core', function (t) { var filenames = Object.keys(cases); @@ -52,11 +53,11 @@ test('core', function (t) { } if (r.body !== undefined) { - t.equal(body, r.body, 'body for `' + file + '`'); + t.equal(eol.lf(body), r.body, 'body for `' + file + '`'); } if (r.location !== undefined) { - t.equal(res.headers.location, path.join('/', baseDir, r.location), 'location for `' + file + '`'); + t.equal(path.normalize(res.headers.location), path.join('/', baseDir, r.location), 'location for `' + file + '`'); } if (--pending === 0) { diff --git a/test/custom-content-type-file-secret.js b/test/custom-content-type-file-secret.js index b87d7ed..deb9bfc 100644 --- a/test/custom-content-type-file-secret.js +++ b/test/custom-content-type-file-secret.js @@ -3,23 +3,16 @@ var test = require('tap').test, request = require('request'), ecstatic = require('../'); -function setup(opts) { - return http.createServer(ecstatic(opts)); -} -function teardown(opts) { - opts = opts || {}; - opts.server.close(function() { - opts.t && opts.t.end(); - process.stderr.write('# server not closing; slaughtering process.\n'); - process.exit(0); - }); -} - test('custom contentType via .types file', function(t) { - var server = setup({ - root: __dirname + '/public/', - 'mime-types': 'secret/custom_mime_type.types' - }); + try { + var server = http.createServer(ecstatic({ + root: __dirname + '/public/', + mimetypes: __dirname + '/secret/custom_mime_type.types' + })); + } catch (e) { + t.fail(e.message); + t.end(); + } t.plan(3) @@ -27,9 +20,18 @@ test('custom contentType via .types file', function(t) { var port = server.address().port; request.get('http://localhost:' + port + '/custom_mime_type.opml', function(err, res, body) { t.ifError(err); - t.equal(res.statusCode, 200); + t.equal(res.statusCode, 200, 'custom_mime_type.opml should be found'); t.equal(res.headers['content-type'], 'application/secret; charset=utf-8'); - teardown({ t:t, server:server }); + server.close(function() { t.end(); }); }); }); }); + +// test('server teardown', function (t) { +// server.close(function() { t.end(); }); + +// var to = setTimeout(function () { +// process.stderr.write('# server not closing; slaughtering process.\n'); +// process.exit(0); +// }, 5000); +// }); diff --git a/test/custom-content-type-file.js b/test/custom-content-type-file.js index 472cd95..a24d064 100644 --- a/test/custom-content-type-file.js +++ b/test/custom-content-type-file.js @@ -6,41 +6,49 @@ var test = require('tap').test, function setup(opts) { return http.createServer(ecstatic(opts)); } -function teardown(opts) { - opts = opts || {}; - opts.server.close(function() { - opts.t && opts.t.end(); - process.stderr.write('# server not closing; slaughtering process.\n'); - process.exit(0); - }); -} + +test('throws when custom contentType .types file does not exist', function(t) { + t.plan(1); + + t.throws( + setup.bind(null, { + root: __dirname + '/public/', + mimeTypes: 'this_file_does_not_exist.types' + }) + ); + +}); test('custom contentType via .types file', function(t) { - var server = setup({ - 'mime-types': 'public/custom_mime_type.types' - }); + try { + var server = setup({ + root: __dirname + '/public', + 'mime-types': __dirname + '/public/custom_mime_type.types' + }); + } catch (e) { + t.fail(e.message); + t.end(); + } t.plan(3) server.listen(0, function() { var port = server.address().port; + request.get('http://localhost:' + port + '/custom_mime_type.opml', function(err, res, body) { t.ifError(err); - t.equal(res.statusCode, 200); + t.equal(res.statusCode, 200, 'custom_mime_type.opml should be found'); t.equal(res.headers['content-type'], 'application/foo; charset=utf-8'); - teardown({ t:t, server:server }); + server.close(function() { t.end(); }); }); }); }); -test('throws when custom contentType .types file does not exist', function(t) { - t.plan(1); +// test('server teardown', function (t) { +// server.close(function() { t.end(); }); - t.throws( - setup.bind(null, { - root: __dirname + '/public/', - mimeTypes: 'this_file_does_not_exist.types' - }) - ); - -}); +// var to = setTimeout(function () { +// process.stderr.write('# server not closing; slaughtering process.\n'); +// process.exit(0); +// }, 5000); +// }); diff --git a/test/custom-content-type.js b/test/custom-content-type.js index 16e2ecb..e7e4bab 100644 --- a/test/custom-content-type.js +++ b/test/custom-content-type.js @@ -3,25 +3,18 @@ var test = require('tap').test, request = require('request'), ecstatic = require('../'); -function setup(opts) { - return http.createServer(ecstatic(opts)); -} -function teardown(opts) { - opts = opts || {}; - opts.server.close(function() { - opts.t && opts.t.end(); - process.stderr.write('# server not closing; slaughtering process.\n'); - process.exit(0); - }); -} - test('custom contentType', function(t) { - var server = setup({ - root: __dirname + '/public/', - mimetype: { - 'application/jon': ['opml'] - } - }); + try { + var server = http.createServer(ecstatic({ + root: __dirname + '/public/', + mimetype: { + 'application/jon': ['opml'] + } + })); + } catch (e) { + t.fail(e.message); + t.end(); + } t.plan(3); @@ -29,9 +22,9 @@ test('custom contentType', function(t) { var port = server.address().port; request.get('http://localhost:' + port + '/custom_mime_type.opml', function(err, res, body) { t.ifError(err); - t.equal(res.statusCode, 200); + t.equal(res.statusCode, 200, 'custom_mime_type.opml should be found'); t.equal(res.headers['content-type'], 'application/jon; charset=utf-8'); - teardown({ t:t, server:server }); + server.close(function() { t.end(); }); }); }); }); diff --git a/test/default-default-ext.js b/test/default-default-ext.js index f1ff97d..57b2a70 100644 --- a/test/default-default-ext.js +++ b/test/default-default-ext.js @@ -1,19 +1,20 @@ var test = require('tap').test, ecstatic = require('../'), http = require('http'), - request = require('request'); + request = require('request'), + eol = require('eol'); test('default defaultExt', function (t) { t.plan(3); var server = http.createServer(ecstatic(__dirname + '/public/subdir')); - t.on('end', function () { server.close() }) server.listen(0, function () { var port = server.address().port; request.get('http://localhost:' + port, function (err, res, body) { t.ifError(err); t.equal(res.statusCode, 200); - t.equal(body, 'index!!!\n'); + t.equal(eol.lf(body), 'index!!!\n'); + server.close(function() { t.end(); }); }); }); }); diff --git a/test/escaping.js b/test/escaping.js index 771ffd7..8ada877 100644 --- a/test/escaping.js +++ b/test/escaping.js @@ -1,30 +1,19 @@ var test = require('tap').test, ecstatic = require('../'), http = require('http'), - request = require('request'); - -var server; + request = require('request'), + eol = require('eol'); test('escaping special characters', function (t) { - server = http.createServer(ecstatic(__dirname + '/public')); + var server = http.createServer(ecstatic(__dirname + '/public')); server.listen(0, function () { var port = server.address().port; request.get('http://localhost:' + port + "/curimit%40gmail.com%20(40%25)", function (err, res, body) { t.ifError(err); t.equal(res.statusCode, 200); - t.equal(body, 'index!!!\n'); - t.end(); + t.equal(eol.lf(body), 'index!!!\n'); + server.close(function() { t.end(); }); }); }); }); - -test('server teardown', function (t) { - server.close(); - - var to = setTimeout(function () { - process.stderr.write('# server not closing; slaughtering process.\n'); - process.exit(0); - }, 5000); - t.end(); -}); diff --git a/test/express-error.js b/test/express-error.js index b3ee033..2ae8b17 100644 --- a/test/express-error.js +++ b/test/express-error.js @@ -12,7 +12,7 @@ var root = __dirname + '/public', mkdirp.sync(root + '/emptyDir'); -var cases = require('./common-cases-error'); +var cases = require('./secret/common-cases-error'); test('express', function (t) { var filenames = Object.keys(cases); diff --git a/test/express.js b/test/express.js index 9f6e3fb..c99d99c 100644 --- a/test/express.js +++ b/test/express.js @@ -5,14 +5,15 @@ var test = require('tap').test, request = require('request'), mkdirp = require('mkdirp'), fs = require('fs'), - path = require('path'); + path = require('path'), + eol = require('eol'); var root = __dirname + '/public', baseDir = 'base'; mkdirp.sync(root + '/emptyDir'); -var cases = require('./common-cases'); +var cases = require('./secret/common-cases'); test('express', function (t) { var filenames = Object.keys(cases); @@ -60,7 +61,7 @@ test('express', function (t) { } if (r.body !== undefined) { - t.equal(body, r.body, 'body for `' + file + '`'); + t.equal(eol.lf(body), r.body, 'body for `' + file + '`'); } if (--pending === 0) { diff --git a/test/html-reflection.js b/test/html-reflection.js index 4543cdc..f399096 100644 --- a/test/html-reflection.js +++ b/test/html-reflection.js @@ -3,10 +3,8 @@ var test = require('tap').test, http = require('http'), request = require('request'); -var server; - test('html reflection prevented', function (t) { - server = http.createServer(ecstatic(__dirname + '/public/containsSymlink')); + var server = http.createServer(ecstatic(__dirname + '/public/containsSymlink')); server.listen(0, function () { var port = server.address().port; @@ -16,17 +14,7 @@ test('html reflection prevented', function (t) { body.indexOf(attack) != -1) { t.fail('Unescaped HTML reflected with vulnerable or missing content-type.'); } - t.end(); + server.close(function() { t.end(); }); }); }); }); - -test('server teardown', function (t) { - server.close(); - - var to = setTimeout(function () { - process.stderr.write('# server not closing; slaughtering process.\n'); - process.exit(0); - }, 5000); - t.end(); -}); diff --git a/test/malformed-dir.js b/test/malformed-dir.js index 388a85e..6ef24ab 100644 --- a/test/malformed-dir.js +++ b/test/malformed-dir.js @@ -1,12 +1,9 @@ var test = require('tap').test, ecstatic = require('../lib/ecstatic'), - http = require('http') -; - -var server; + http = require('http'); test('malformed showdir uri', function (t) { - server = http.createServer(ecstatic(__dirname, { showDir: true })); + var server = http.createServer(ecstatic(__dirname, { showDir: true })); server.listen(0, function () { var r = http.get({ @@ -16,17 +13,7 @@ test('malformed showdir uri', function (t) { }); r.on('response', function (res) { t.equal(res.statusCode, 400); - t.end(); + server.close(function() { t.end(); }); }); }); }); - -test('server teardown', function (t) { - server.close(); - - var to = setTimeout(function () { - process.stderr.write('# server not closing; slaughtering process.\n'); - process.exit(0); - }, 5000); - t.end(); -}); diff --git a/test/malformed.js b/test/malformed.js index 1af17ee..7a11f3b 100644 --- a/test/malformed.js +++ b/test/malformed.js @@ -1,9 +1,6 @@ var test = require('tap').test, ecstatic = require('../lib/ecstatic'), - http = require('http') -; - -var server; + http = require('http'); test('malformed uri', function (t) { server = http.createServer(ecstatic(__dirname)); @@ -16,17 +13,8 @@ test('malformed uri', function (t) { }); r.on('response', function (res) { t.equal(res.statusCode, 400); - t.end(); + server.close(function() { t.end(); }); }); }); }); -test('server teardown', function (t) { - server.close(); - - var to = setTimeout(function () { - process.stderr.write('# server not closing; slaughtering process.\n'); - process.exit(0); - }, 5000); - t.end(); -}); diff --git a/test/mime.js b/test/mime.js index 239b5ce..9130623 100644 --- a/test/mime.js +++ b/test/mime.js @@ -1,17 +1,7 @@ var test = require('tap').test, - mime; - -function setup() { - mime = require('mime'); -} -function teardown(t) { - t && t.end(); - mime = null; -} + mime = require('mime'); test('mime package lookup', function(t) { - setup(); - t.plan(4); t.equal(mime.lookup('/path/to/file.txt'), 'text/plain'); @@ -19,12 +9,10 @@ test('mime package lookup', function(t) { t.equal(mime.lookup('.TXT'), 'text/plain'); t.equal(mime.lookup('htm'), 'text/html'); - teardown(t); + t.end(); }); test('custom definition of mime-type with the mime package', function(t) { - setup(); - t.plan(1); mime.define({ @@ -32,18 +20,22 @@ test('custom definition of mime-type with the mime package', function(t) { }); t.equal(mime.lookup('.opml'), 'application/xml'); - teardown(t); + t.end(); }); test('custom definition of mime-type with a .types file', function(t) { - setup(); - t.plan(2); - mime.load('public/custom_mime_type.types'); + try { + mime.load('test/public/custom_mime_type.types'); + } catch (e) { + t.fail(e.message); + t.end(); + } + t.equal(mime.lookup('.opml'), 'application/foo'); // see public/custom_mime_type.types t.throws( mime.load.bind(mime, 'public/this_file_does_not_exist.types') ); - teardown(t); + t.end(); }); diff --git a/test/public/d.js b/test/public/d.js index fc9ebc0..7ab25e5 120000 --- a/test/public/d.js +++ b/test/public/d.js @@ -1 +1 @@ -c.js \ No newline at end of file +d.js diff --git a/test/range.js b/test/range.js index 1d404a1..b258071 100644 --- a/test/range.js +++ b/test/range.js @@ -1,7 +1,8 @@ var test = require('tap').test, ecstatic = require('../'), http = require('http'), - request = require('request'); + request = require('request'), + eol = require('eol'); test('range', function (t) { t.plan(4); @@ -37,7 +38,7 @@ test('range past the end', function (t) { request.get(opts, function (err, res, body) { t.ifError(err); t.equal(res.statusCode, 206, 'partial content status code'); - t.equal(body, 'e!!\n'); + t.equal(eol.lf(body), 'e!!\n'); t.equal(parseInt(res.headers['content-length']), body.length); }); }); @@ -95,7 +96,7 @@ test('partial range', function (t) { request.get(opts, function (err, res, body) { t.ifError(err); t.equal(res.statusCode, 206, 'partial content status code'); - t.equal(body, 'e!!\n'); + t.equal(eol.lf(body), 'e!!\n'); t.equal(parseInt(res.headers['content-length']), body.length); t.equal(res.headers['content-range'], 'bytes 3-10/11'); }); diff --git a/test/common-cases-error.js b/test/secret/common-cases-error.js similarity index 100% rename from test/common-cases-error.js rename to test/secret/common-cases-error.js diff --git a/test/common-cases.js b/test/secret/common-cases.js similarity index 94% rename from test/common-cases.js rename to test/secret/common-cases.js index 7c8b803..9d0e37a 100644 --- a/test/common-cases.js +++ b/test/secret/common-cases.js @@ -20,7 +20,7 @@ module.exports = { 'd.js' : { code : 200, type : 'application/javascript', - body : 'console.log(\'C!!!\');\n', + body : 'd.js\n', }, 'e.js' : { code : 200, @@ -85,7 +85,7 @@ module.exports = { code : 200, file: 'compress/foo.js.gz', headers: {'accept-encoding': 'compress, gzip'}, - body: fs.readFileSync(path.join(__dirname, 'public', 'compress', 'foo.js.gz'), 'utf8') + body: fs.readFileSync(path.join(__dirname, '../', 'public', 'compress', 'foo.js.gz'), 'utf8') }, // no accept-encoding of gzip, so serve regular file 'compress/foo_2.js' : { diff --git a/test/union-multiple-folders-cases.js b/test/secret/union-multiple-folders-cases.js similarity index 100% rename from test/union-multiple-folders-cases.js rename to test/secret/union-multiple-folders-cases.js diff --git a/test/union-error.js b/test/union-error.js index 79b063e..b3fa675 100644 --- a/test/union-error.js +++ b/test/union-error.js @@ -11,7 +11,7 @@ var root = __dirname + '/public', mkdirp.sync(root + '/emptyDir'); -var cases = require('./common-cases-error'); +var cases = require('./secret/common-cases-error'); test('union', function (t) { var filenames = Object.keys(cases); diff --git a/test/union-multiple-folders.js b/test/union-multiple-folders.js index ff1ecbe..db2dbe8 100644 --- a/test/union-multiple-folders.js +++ b/test/union-multiple-folders.js @@ -4,7 +4,8 @@ var test = require('tap').test, request = require('request'), mkdirp = require('mkdirp'), fs = require('fs'), - path = require('path'); + path = require('path'), + eol = require('eol'); var subdir = __dirname + '/public/subdir', anotherSubdir = __dirname + '/public/another-subdir', @@ -12,7 +13,7 @@ var subdir = __dirname + '/public/subdir', mkdirp.sync(root + '/emptyDir'); -var cases = require('./union-multiple-folders-cases'); +var cases = require('./secret/union-multiple-folders-cases'); test('union', function(t) { var filenames = Object.keys(cases); @@ -63,7 +64,7 @@ test('union', function(t) { } if (r.body !== undefined) { - t.equal(body, r.body, 'body for `' + file + '`'); + t.equal(eol.lf(body), r.body, 'body for `' + file + '`'); } if (--pending === 0) { diff --git a/test/union.js b/test/union.js index b5f23ad..251603a 100644 --- a/test/union.js +++ b/test/union.js @@ -4,14 +4,15 @@ var test = require('tap').test, request = require('request'), mkdirp = require('mkdirp'), fs = require('fs'), - path = require('path'); + path = require('path'), + eol = require('eol'); var root = __dirname + '/public', baseDir = 'base'; mkdirp.sync(root + '/emptyDir'); -var cases = require('./common-cases'); +var cases = require('./secret/common-cases'); test('union', function (t) { var filenames = Object.keys(cases); @@ -54,7 +55,7 @@ test('union', function (t) { } if (r.body !== undefined) { - t.equal(body, r.body, 'body for `' + file + '`'); + t.equal(eol.lf(body), r.body, 'body for `' + file + '`'); } if (--pending === 0) { From e18ff2ae030f75e7294e757c2d375fefc1042080 Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Tue, 12 May 2015 20:48:43 +0200 Subject: [PATCH 18/33] change test command to work with tap 1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6d0d077..a60aad6 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ }, "main": "./lib/ecstatic.js", "scripts": { - "test": "tap test/*.js" + "test": "tap test" }, "bin": "./lib/ecstatic.js", "keywords": [ From 554ee197952abbe465cbdd9736edd27440cbc09e Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Tue, 12 May 2015 20:53:32 +0200 Subject: [PATCH 19/33] reverting back to originale implementation for root --- lib/ecstatic.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ecstatic.js b/lib/ecstatic.js index b494546..abe1dee 100755 --- a/lib/ecstatic.js +++ b/lib/ecstatic.js @@ -19,7 +19,7 @@ var ecstatic = module.exports = function (dir, options) { dir = options.root; } - var root = dir && path.join(path.resolve(dir), '/'), + var root = path.join(path.resolve(dir), '/'), opts = optsParser(options), cache = opts.cache, autoIndex = opts.autoIndex, From 20cf5679f45d369e57e94b4dbb78f9c5e45e1425 Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Tue, 12 May 2015 20:59:44 +0200 Subject: [PATCH 20/33] try to fix npm test on travis (it's different from windows) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a60aad6..6d0d077 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ }, "main": "./lib/ecstatic.js", "scripts": { - "test": "tap test" + "test": "tap test/*.js" }, "bin": "./lib/ecstatic.js", "keywords": [ From ee676d12f62d302592f843b2287cd406510b1bf5 Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Tue, 12 May 2015 21:21:32 +0200 Subject: [PATCH 21/33] try to create a test command that works both on windows and linux --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6d0d077..dea1f09 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ }, "main": "./lib/ecstatic.js", "scripts": { - "test": "tap test/*.js" + "test": "tap test/" }, "bin": "./lib/ecstatic.js", "keywords": [ From ffbeac3ceaaec7ada05911640c7fab72996a883d Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Tue, 12 May 2015 21:22:07 +0200 Subject: [PATCH 22/33] resolved test error due to platform differency - resolution: test for different bytes on windows --- test/range.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/range.js b/test/range.js index b258071..c4d2f7c 100644 --- a/test/range.js +++ b/test/range.js @@ -83,6 +83,7 @@ test('flipped range', function (t) { }); test('partial range', function (t) { + // 1 test is platform depedent "res.headers['content-range']" t.plan(5); var server = http.createServer(ecstatic(__dirname + '/public/subdir')); t.on('end', function () { server.close() }) @@ -98,7 +99,12 @@ test('partial range', function (t) { t.equal(res.statusCode, 206, 'partial content status code'); t.equal(eol.lf(body), 'e!!\n'); t.equal(parseInt(res.headers['content-length']), body.length); - t.equal(res.headers['content-range'], 'bytes 3-10/11'); + + if (process.platform === 'win32') { + t.equal(res.headers['content-range'], 'bytes 3-11/12'); + } else { + t.equal(res.headers['content-range'], 'bytes 3-10/11'); + } }); }); }); From 617639b608044c3041f5bd967ebd72aab4bce212 Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Tue, 12 May 2015 21:52:21 +0200 Subject: [PATCH 23/33] fix npm test on linux (travis) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dea1f09..6d0d077 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ }, "main": "./lib/ecstatic.js", "scripts": { - "test": "tap test/" + "test": "tap test/*.js" }, "bin": "./lib/ecstatic.js", "keywords": [ From 6bcaf4cdb6ddfb807e7dec1cc23c7f9749e66af0 Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Tue, 12 May 2015 21:59:25 +0200 Subject: [PATCH 24/33] update tap to version 1.0.3 - now we can run the test cross-platform - well, on windows and linux at least... --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6d0d077..23513a7 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "express": "^4.12.3", "mkdirp": "^0.5.0", "request": "^2.49.0", - "tap": "^1.0.2", + "tap": "^1.0.3", "union": "^0.4.4" } } From 7a23cef0c6fd49d89c2dbb18a1d53975255180ae Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Tue, 12 May 2015 22:32:37 +0200 Subject: [PATCH 25/33] change to npm test to what-ever @isaacs says :) --- .settings/launch.json | 33 + .settings/settings.json | 5 + package.json | 2 +- typings/node/node.d.ts | 1519 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 1558 insertions(+), 1 deletion(-) create mode 100644 .settings/launch.json create mode 100644 .settings/settings.json create mode 100644 typings/node/node.d.ts diff --git a/.settings/launch.json b/.settings/launch.json new file mode 100644 index 0000000..4b7de2c --- /dev/null +++ b/.settings/launch.json @@ -0,0 +1,33 @@ +{ + "version": "0.1.0", + // List of configurations. Add new configurations or edit existing ones. + // ONLY "node" and "mono" are supported, change "type" to switch. + "configurations": [ + { + // Name of configuration; appears in the launch configuration drop down menu. + "name": "Launch app.js", + // Type of configuration. Possible values: "node", "mono". + "type": "node", + // Workspace relative or absolute path to the program. + "program": "./node_modules/.bin/tap", + // Automatically stop program after launch. + "stopOnEntry": true, + // Command line arguments passed to the program. + "args": [" ./test/custom-content-type-file-secret.js"], + // Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace. + "cwd": ".", + // Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH. + "runtimeExecutable": null, + // Environment variables passed to the program. + "env": { } + }, + { + "name": "Attach", + "type": "node", + // TCP/IP address. Default is "localhost". + "address": "localhost", + // Port to attach to. + "port": 5858 + } + ] +} diff --git a/.settings/settings.json b/.settings/settings.json new file mode 100644 index 0000000..e234268 --- /dev/null +++ b/.settings/settings.json @@ -0,0 +1,5 @@ +// Place your settings in this file to overwrite default and user settings. +{ + "editor.insertSpaces": true, + "editor.tabSize": 2 +} \ No newline at end of file diff --git a/package.json b/package.json index 23513a7..229422e 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ }, "main": "./lib/ecstatic.js", "scripts": { - "test": "tap test/*.js" + "test": "tap test/" }, "bin": "./lib/ecstatic.js", "keywords": [ diff --git a/typings/node/node.d.ts b/typings/node/node.d.ts new file mode 100644 index 0000000..b0a7b77 --- /dev/null +++ b/typings/node/node.d.ts @@ -0,0 +1,1519 @@ +// Type definitions for Node.js v0.12.0 +// Project: http://nodejs.org/ +// Definitions by: Microsoft TypeScript , DefinitelyTyped +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/************************************************ +* * +* Node.js v0.12.0 API * +* * +************************************************/ + +/************************************************ +* * +* GLOBAL * +* * +************************************************/ +declare var process: NodeJS.Process; +declare var global: NodeJS.Global; + +declare var __filename: string; +declare var __dirname: string; + +declare function setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer; +declare function clearTimeout(timeoutId: NodeJS.Timer): void; +declare function setInterval(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer; +declare function clearInterval(intervalId: NodeJS.Timer): void; +declare function setImmediate(callback: (...args: any[]) => void, ...args: any[]): any; +declare function clearImmediate(immediateId: any): void; + +declare var require: { + (id: string): any; + resolve(id:string): string; + cache: any; + extensions: any; + main: any; +}; + +declare var module: { + exports: any; + require(id: string): any; + id: string; + filename: string; + loaded: boolean; + parent: any; + children: any[]; +}; + +// Same as module.exports +declare var exports: any; +declare var SlowBuffer: { + new (str: string, encoding?: string): Buffer; + new (size: number): Buffer; + new (size: Uint8Array): Buffer; + new (array: any[]): Buffer; + prototype: Buffer; + isBuffer(obj: any): boolean; + byteLength(string: string, encoding?: string): number; + concat(list: Buffer[], totalLength?: number): Buffer; +}; + + +// Buffer class +interface Buffer extends NodeBuffer {} +declare var Buffer: { + new (str: string, encoding?: string): Buffer; + new (size: number): Buffer; + new (size: Uint8Array): Buffer; + new (array: any[]): Buffer; + prototype: Buffer; + isBuffer(obj: any): boolean; + byteLength(string: string, encoding?: string): number; + concat(list: Buffer[], totalLength?: number): Buffer; +}; + +/************************************************ +* * +* GLOBAL INTERFACES * +* * +************************************************/ +declare module NodeJS { + export interface ErrnoException extends Error { + errno?: number; + code?: string; + path?: string; + syscall?: string; + } + + export interface EventEmitter { + addListener(event: string, listener: Function): EventEmitter; + on(event: string, listener: Function): EventEmitter; + once(event: string, listener: Function): EventEmitter; + removeListener(event: string, listener: Function): EventEmitter; + removeAllListeners(event?: string): EventEmitter; + setMaxListeners(n: number): void; + listeners(event: string): Function[]; + emit(event: string, ...args: any[]): boolean; + } + + export interface ReadableStream extends EventEmitter { + readable: boolean; + read(size?: number): string|Buffer; + setEncoding(encoding: string): void; + pause(): void; + resume(): void; + pipe(destination: T, options?: { end?: boolean; }): T; + unpipe(destination?: T): void; + unshift(chunk: string): void; + unshift(chunk: Buffer): void; + wrap(oldStream: ReadableStream): ReadableStream; + } + + export interface WritableStream extends EventEmitter { + writable: boolean; + write(buffer: Buffer, cb?: Function): boolean; + write(str: string, cb?: Function): boolean; + write(str: string, encoding?: string, cb?: Function): boolean; + end(): void; + end(buffer: Buffer, cb?: Function): void; + end(str: string, cb?: Function): void; + end(str: string, encoding?: string, cb?: Function): void; + } + + export interface ReadWriteStream extends ReadableStream, WritableStream {} + + export interface Process extends EventEmitter { + stdout: WritableStream; + stderr: WritableStream; + stdin: ReadableStream; + argv: string[]; + execPath: string; + abort(): void; + chdir(directory: string): void; + cwd(): string; + env: any; + exit(code?: number): void; + getgid(): number; + setgid(id: number): void; + setgid(id: string): void; + getuid(): number; + setuid(id: number): void; + setuid(id: string): void; + version: string; + versions: { + http_parser: string; + node: string; + v8: string; + ares: string; + uv: string; + zlib: string; + openssl: string; + }; + config: { + target_defaults: { + cflags: any[]; + default_configuration: string; + defines: string[]; + include_dirs: string[]; + libraries: string[]; + }; + variables: { + clang: number; + host_arch: string; + node_install_npm: boolean; + node_install_waf: boolean; + node_prefix: string; + node_shared_openssl: boolean; + node_shared_v8: boolean; + node_shared_zlib: boolean; + node_use_dtrace: boolean; + node_use_etw: boolean; + node_use_openssl: boolean; + target_arch: string; + v8_no_strict_aliasing: number; + v8_use_snapshot: boolean; + visibility: string; + }; + }; + kill(pid: number, signal?: string): void; + pid: number; + title: string; + arch: string; + platform: string; + memoryUsage(): { rss: number; heapTotal: number; heapUsed: number; }; + nextTick(callback: Function): void; + umask(mask?: number): number; + uptime(): number; + hrtime(time?:number[]): number[]; + + // Worker + send?(message: any, sendHandle?: any): void; + } + + export interface Global { + Array: typeof Array; + ArrayBuffer: typeof ArrayBuffer; + Boolean: typeof Boolean; + Buffer: typeof Buffer; + DataView: typeof DataView; + Date: typeof Date; + Error: typeof Error; + EvalError: typeof EvalError; + Float32Array: typeof Float32Array; + Float64Array: typeof Float64Array; + Function: typeof Function; + GLOBAL: Global; + Infinity: typeof Infinity; + Int16Array: typeof Int16Array; + Int32Array: typeof Int32Array; + Int8Array: typeof Int8Array; + Intl: typeof Intl; + JSON: typeof JSON; + Map: typeof Map; + Math: typeof Math; + NaN: typeof NaN; + Number: typeof Number; + Object: typeof Object; + Promise: Function; + RangeError: typeof RangeError; + ReferenceError: typeof ReferenceError; + RegExp: typeof RegExp; + Set: typeof Set; + String: typeof String; + Symbol: Function; + SyntaxError: typeof SyntaxError; + TypeError: typeof TypeError; + URIError: typeof URIError; + Uint16Array: typeof Uint16Array; + Uint32Array: typeof Uint32Array; + Uint8Array: typeof Uint8Array; + Uint8ClampedArray: Function; + WeakMap: typeof WeakMap; + WeakSet: Function; + clearImmediate: (immediateId: any) => void; + clearInterval: (intervalId: NodeJS.Timer) => void; + clearTimeout: (timeoutId: NodeJS.Timer) => void; + console: typeof console; + decodeURI: typeof decodeURI; + decodeURIComponent: typeof decodeURIComponent; + encodeURI: typeof encodeURI; + encodeURIComponent: typeof encodeURIComponent; + escape: (str: string) => string; + eval: typeof eval; + global: Global; + isFinite: typeof isFinite; + isNaN: typeof isNaN; + parseFloat: typeof parseFloat; + parseInt: typeof parseInt; + process: Process; + root: Global; + setImmediate: (callback: (...args: any[]) => void, ...args: any[]) => any; + setInterval: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => NodeJS.Timer; + setTimeout: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => NodeJS.Timer; + undefined: typeof undefined; + unescape: (str: string) => string; + } + + export interface Timer { + ref() : void; + unref() : void; + } +} + +/** + * @deprecated + */ +interface NodeBuffer { + [index: number]: number; + write(string: string, offset?: number, length?: number, encoding?: string): number; + toString(encoding?: string, start?: number, end?: number): string; + toJSON(): any; + length: number; + copy(targetBuffer: Buffer, targetStart?: number, sourceStart?: number, sourceEnd?: number): number; + slice(start?: number, end?: number): Buffer; + readUInt8(offset: number, noAsset?: boolean): number; + readUInt16LE(offset: number, noAssert?: boolean): number; + readUInt16BE(offset: number, noAssert?: boolean): number; + readUInt32LE(offset: number, noAssert?: boolean): number; + readUInt32BE(offset: number, noAssert?: boolean): number; + readInt8(offset: number, noAssert?: boolean): number; + readInt16LE(offset: number, noAssert?: boolean): number; + readInt16BE(offset: number, noAssert?: boolean): number; + readInt32LE(offset: number, noAssert?: boolean): number; + readInt32BE(offset: number, noAssert?: boolean): number; + readFloatLE(offset: number, noAssert?: boolean): number; + readFloatBE(offset: number, noAssert?: boolean): number; + readDoubleLE(offset: number, noAssert?: boolean): number; + readDoubleBE(offset: number, noAssert?: boolean): number; + writeUInt8(value: number, offset: number, noAssert?: boolean): void; + writeUInt16LE(value: number, offset: number, noAssert?: boolean): void; + writeUInt16BE(value: number, offset: number, noAssert?: boolean): void; + writeUInt32LE(value: number, offset: number, noAssert?: boolean): void; + writeUInt32BE(value: number, offset: number, noAssert?: boolean): void; + writeInt8(value: number, offset: number, noAssert?: boolean): void; + writeInt16LE(value: number, offset: number, noAssert?: boolean): void; + writeInt16BE(value: number, offset: number, noAssert?: boolean): void; + writeInt32LE(value: number, offset: number, noAssert?: boolean): void; + writeInt32BE(value: number, offset: number, noAssert?: boolean): void; + writeFloatLE(value: number, offset: number, noAssert?: boolean): void; + writeFloatBE(value: number, offset: number, noAssert?: boolean): void; + writeDoubleLE(value: number, offset: number, noAssert?: boolean): void; + writeDoubleBE(value: number, offset: number, noAssert?: boolean): void; + fill(value: any, offset?: number, end?: number): void; +} + +/************************************************ +* * +* MODULES * +* * +************************************************/ +declare module "buffer" { + export var INSPECT_MAX_BYTES: number; +} + +declare module "querystring" { + export function stringify(obj: any, sep?: string, eq?: string): string; + export function parse(str: string, sep?: string, eq?: string, options?: { maxKeys?: number; }): any; + export function escape(str: string): string; + export function unescape(str: string): string; +} + +declare module "events" { + export class EventEmitter implements NodeJS.EventEmitter { + static listenerCount(emitter: EventEmitter, event: string): number; + + addListener(event: string, listener: Function): EventEmitter; + on(event: string, listener: Function): EventEmitter; + once(event: string, listener: Function): EventEmitter; + removeListener(event: string, listener: Function): EventEmitter; + removeAllListeners(event?: string): EventEmitter; + setMaxListeners(n: number): void; + listeners(event: string): Function[]; + emit(event: string, ...args: any[]): boolean; + } +} + +declare module "http" { + import events = require("events"); + import net = require("net"); + import stream = require("stream"); + + export interface Server extends events.EventEmitter { + listen(port: number, hostname?: string, backlog?: number, callback?: Function): Server; + listen(port: number, hostname?: string, callback?: Function): Server; + listen(path: string, callback?: Function): Server; + listen(handle: any, listeningListener?: Function): Server; + close(cb?: any): Server; + address(): { port: number; family: string; address: string; }; + maxHeadersCount: number; + } + /** + * @deprecated Use IncomingMessage + */ + export interface ServerRequest extends IncomingMessage { + connection: net.Socket; + } + export interface ServerResponse extends events.EventEmitter, stream.Writable { + // Extended base methods + write(buffer: Buffer): boolean; + write(buffer: Buffer, cb?: Function): boolean; + write(str: string, cb?: Function): boolean; + write(str: string, encoding?: string, cb?: Function): boolean; + write(str: string, encoding?: string, fd?: string): boolean; + + writeContinue(): void; + writeHead(statusCode: number, reasonPhrase?: string, headers?: any): void; + writeHead(statusCode: number, headers?: any): void; + statusCode: number; + setHeader(name: string, value: string): void; + sendDate: boolean; + getHeader(name: string): string; + removeHeader(name: string): void; + write(chunk: any, encoding?: string): any; + addTrailers(headers: any): void; + + // Extended base methods + end(): void; + end(buffer: Buffer, cb?: Function): void; + end(str: string, cb?: Function): void; + end(str: string, encoding?: string, cb?: Function): void; + end(data?: any, encoding?: string): void; + } + export interface ClientRequest extends events.EventEmitter, stream.Writable { + // Extended base methods + write(buffer: Buffer): boolean; + write(buffer: Buffer, cb?: Function): boolean; + write(str: string, cb?: Function): boolean; + write(str: string, encoding?: string, cb?: Function): boolean; + write(str: string, encoding?: string, fd?: string): boolean; + + write(chunk: any, encoding?: string): void; + abort(): void; + setTimeout(timeout: number, callback?: Function): void; + setNoDelay(noDelay?: boolean): void; + setSocketKeepAlive(enable?: boolean, initialDelay?: number): void; + + // Extended base methods + end(): void; + end(buffer: Buffer, cb?: Function): void; + end(str: string, cb?: Function): void; + end(str: string, encoding?: string, cb?: Function): void; + end(data?: any, encoding?: string): void; + } + export interface IncomingMessage extends events.EventEmitter, stream.Readable { + httpVersion: string; + headers: any; + rawHeaders: string[]; + trailers: any; + rawTrailers: any; + setTimeout(msecs: number, callback: Function): NodeJS.Timer; + /** + * Only valid for request obtained from http.Server. + */ + method?: string; + /** + * Only valid for request obtained from http.Server. + */ + url?: string; + /** + * Only valid for response obtained from http.ClientRequest. + */ + statusCode?: number; + /** + * Only valid for response obtained from http.ClientRequest. + */ + statusMessage?: string; + socket: net.Socket; + } + /** + * @deprecated Use IncomingMessage + */ + export interface ClientResponse extends IncomingMessage { } + + export interface AgentOptions { + /** + * Keep sockets around in a pool to be used by other requests in the future. Default = false + */ + keepAlive?: boolean; + /** + * When using HTTP KeepAlive, how often to send TCP KeepAlive packets over sockets being kept alive. Default = 1000. + * Only relevant if keepAlive is set to true. + */ + keepAliveMsecs?: number; + /** + * Maximum number of sockets to allow per host. Default for Node 0.10 is 5, default for Node 0.12 is Infinity + */ + maxSockets?: number; + /** + * Maximum number of sockets to leave open in a free state. Only relevant if keepAlive is set to true. Default = 256. + */ + maxFreeSockets?: number; + } + + export class Agent { + maxSockets: number; + sockets: any; + requests: any; + + constructor(opts?: AgentOptions); + + /** + * Destroy any sockets that are currently in use by the agent. + * It is usually not necessary to do this. However, if you are using an agent with KeepAlive enabled, + * then it is best to explicitly shut down the agent when you know that it will no longer be used. Otherwise, + * sockets may hang open for quite a long time before the server terminates them. + */ + destroy(): void; + } + + export var STATUS_CODES: { + [errorCode: number]: string; + [errorCode: string]: string; + }; + export function createServer(requestListener?: (request: IncomingMessage, response: ServerResponse) =>void ): Server; + export function createClient(port?: number, host?: string): any; + export function request(options: any, callback?: (res: IncomingMessage) => void): ClientRequest; + export function get(options: any, callback?: (res: IncomingMessage) => void): ClientRequest; + export var globalAgent: Agent; +} + +declare module "cluster" { + import child = require("child_process"); + import events = require("events"); + + export interface ClusterSettings { + exec?: string; + args?: string[]; + silent?: boolean; + } + + export class Worker extends events.EventEmitter { + id: string; + process: child.ChildProcess; + suicide: boolean; + send(message: any, sendHandle?: any): void; + kill(signal?: string): void; + destroy(signal?: string): void; + disconnect(): void; + } + + export var settings: ClusterSettings; + export var isMaster: boolean; + export var isWorker: boolean; + export function setupMaster(settings?: ClusterSettings): void; + export function fork(env?: any): Worker; + export function disconnect(callback?: Function): void; + export var worker: Worker; + export var workers: Worker[]; + + // Event emitter + export function addListener(event: string, listener: Function): void; + export function on(event: string, listener: Function): any; + export function once(event: string, listener: Function): void; + export function removeListener(event: string, listener: Function): void; + export function removeAllListeners(event?: string): void; + export function setMaxListeners(n: number): void; + export function listeners(event: string): Function[]; + export function emit(event: string, ...args: any[]): boolean; +} + +declare module "zlib" { + import stream = require("stream"); + export interface ZlibOptions { chunkSize?: number; windowBits?: number; level?: number; memLevel?: number; strategy?: number; dictionary?: any; } + + export interface Gzip extends stream.Transform { } + export interface Gunzip extends stream.Transform { } + export interface Deflate extends stream.Transform { } + export interface Inflate extends stream.Transform { } + export interface DeflateRaw extends stream.Transform { } + export interface InflateRaw extends stream.Transform { } + export interface Unzip extends stream.Transform { } + + export function createGzip(options?: ZlibOptions): Gzip; + export function createGunzip(options?: ZlibOptions): Gunzip; + export function createDeflate(options?: ZlibOptions): Deflate; + export function createInflate(options?: ZlibOptions): Inflate; + export function createDeflateRaw(options?: ZlibOptions): DeflateRaw; + export function createInflateRaw(options?: ZlibOptions): InflateRaw; + export function createUnzip(options?: ZlibOptions): Unzip; + + export function deflate(buf: Buffer, callback: (error: Error, result: any) =>void ): void; + export function deflateRaw(buf: Buffer, callback: (error: Error, result: any) =>void ): void; + export function gzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; + export function gunzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; + export function inflate(buf: Buffer, callback: (error: Error, result: any) =>void ): void; + export function inflateRaw(buf: Buffer, callback: (error: Error, result: any) =>void ): void; + export function unzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; + + // Constants + export var Z_NO_FLUSH: number; + export var Z_PARTIAL_FLUSH: number; + export var Z_SYNC_FLUSH: number; + export var Z_FULL_FLUSH: number; + export var Z_FINISH: number; + export var Z_BLOCK: number; + export var Z_TREES: number; + export var Z_OK: number; + export var Z_STREAM_END: number; + export var Z_NEED_DICT: number; + export var Z_ERRNO: number; + export var Z_STREAM_ERROR: number; + export var Z_DATA_ERROR: number; + export var Z_MEM_ERROR: number; + export var Z_BUF_ERROR: number; + export var Z_VERSION_ERROR: number; + export var Z_NO_COMPRESSION: number; + export var Z_BEST_SPEED: number; + export var Z_BEST_COMPRESSION: number; + export var Z_DEFAULT_COMPRESSION: number; + export var Z_FILTERED: number; + export var Z_HUFFMAN_ONLY: number; + export var Z_RLE: number; + export var Z_FIXED: number; + export var Z_DEFAULT_STRATEGY: number; + export var Z_BINARY: number; + export var Z_TEXT: number; + export var Z_ASCII: number; + export var Z_UNKNOWN: number; + export var Z_DEFLATED: number; + export var Z_NULL: number; +} + +declare module "os" { + export function tmpdir(): string; + export function hostname(): string; + export function type(): string; + export function platform(): string; + export function arch(): string; + export function release(): string; + export function uptime(): number; + export function loadavg(): number[]; + export function totalmem(): number; + export function freemem(): number; + export function cpus(): { model: string; speed: number; times: { user: number; nice: number; sys: number; idle: number; irq: number; }; }[]; + export function networkInterfaces(): any; + export var EOL: string; +} + +declare module "https" { + import tls = require("tls"); + import events = require("events"); + import http = require("http"); + + export interface ServerOptions { + pfx?: any; + key?: any; + passphrase?: string; + cert?: any; + ca?: any; + crl?: any; + ciphers?: string; + honorCipherOrder?: boolean; + requestCert?: boolean; + rejectUnauthorized?: boolean; + NPNProtocols?: any; + SNICallback?: (servername: string) => any; + } + + export interface RequestOptions { + host?: string; + hostname?: string; + port?: number; + path?: string; + method?: string; + headers?: any; + auth?: string; + agent?: any; + pfx?: any; + key?: any; + passphrase?: string; + cert?: any; + ca?: any; + ciphers?: string; + rejectUnauthorized?: boolean; + } + + export interface Agent { + maxSockets: number; + sockets: any; + requests: any; + } + export var Agent: { + new (options?: RequestOptions): Agent; + }; + export interface Server extends tls.Server { } + export function createServer(options: ServerOptions, requestListener?: Function): Server; + export function request(options: RequestOptions, callback?: (res: http.IncomingMessage) =>void ): http.ClientRequest; + export function get(options: RequestOptions, callback?: (res: http.IncomingMessage) =>void ): http.ClientRequest; + export var globalAgent: Agent; +} + +declare module "punycode" { + export function decode(string: string): string; + export function encode(string: string): string; + export function toUnicode(domain: string): string; + export function toASCII(domain: string): string; + export var ucs2: ucs2; + interface ucs2 { + decode(string: string): string; + encode(codePoints: number[]): string; + } + export var version: any; +} + +declare module "repl" { + import stream = require("stream"); + import events = require("events"); + + export interface ReplOptions { + prompt?: string; + input?: NodeJS.ReadableStream; + output?: NodeJS.WritableStream; + terminal?: boolean; + eval?: Function; + useColors?: boolean; + useGlobal?: boolean; + ignoreUndefined?: boolean; + writer?: Function; + } + export function start(options: ReplOptions): events.EventEmitter; +} + +declare module "readline" { + import events = require("events"); + import stream = require("stream"); + + export interface ReadLine extends events.EventEmitter { + setPrompt(prompt: string, length: number): void; + prompt(preserveCursor?: boolean): void; + question(query: string, callback: Function): void; + pause(): void; + resume(): void; + close(): void; + write(data: any, key?: any): void; + } + export interface ReadLineOptions { + input: NodeJS.ReadableStream; + output: NodeJS.WritableStream; + completer?: Function; + terminal?: boolean; + } + export function createInterface(options: ReadLineOptions): ReadLine; +} + +declare module "vm" { + export interface Context { } + export interface Script { + runInThisContext(): void; + runInNewContext(sandbox?: Context): void; + } + export function runInThisContext(code: string, filename?: string): void; + export function runInNewContext(code: string, sandbox?: Context, filename?: string): void; + export function runInContext(code: string, context: Context, filename?: string): void; + export function createContext(initSandbox?: Context): Context; + export function createScript(code: string, filename?: string): Script; +} + +declare module "child_process" { + import events = require("events"); + import stream = require("stream"); + + export interface ChildProcess extends events.EventEmitter { + stdin: stream.Writable; + stdout: stream.Readable; + stderr: stream.Readable; + pid: number; + kill(signal?: string): void; + send(message: any, sendHandle?: any): void; + disconnect(): void; + } + + export function spawn(command: string, args?: string[], options?: { + cwd?: string; + stdio?: any; + custom?: any; + env?: any; + detached?: boolean; + }): ChildProcess; + export function exec(command: string, options: { + cwd?: string; + stdio?: any; + customFds?: any; + env?: any; + encoding?: string; + timeout?: number; + maxBuffer?: number; + killSignal?: string; + }, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; + export function exec(command: string, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; + export function execFile(file: string, + callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; + export function execFile(file: string, args?: string[], + callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; + export function execFile(file: string, args?: string[], options?: { + cwd?: string; + stdio?: any; + customFds?: any; + env?: any; + encoding?: string; + timeout?: number; + maxBuffer?: string; + killSignal?: string; + }, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; + export function fork(modulePath: string, args?: string[], options?: { + cwd?: string; + env?: any; + encoding?: string; + }): ChildProcess; + export function execSync(command: string, options?: { + cwd?: string; + input?: string|Buffer; + stdio?: any; + env?: any; + uid?: number; + gid?: number; + timeout?: number; + maxBuffer?: number; + killSignal?: string; + encoding?: string; + }): ChildProcess; + export function execFileSync(command: string, args?: string[], options?: { + cwd?: string; + input?: string|Buffer; + stdio?: any; + env?: any; + uid?: number; + gid?: number; + timeout?: number; + maxBuffer?: number; + killSignal?: string; + encoding?: string; + }): ChildProcess; +} + +declare module "url" { + export interface Url { + href: string; + protocol: string; + auth: string; + hostname: string; + port: string; + host: string; + pathname: string; + search: string; + query: any; // string | Object + slashes: boolean; + hash?: string; + path?: string; + } + + export interface UrlOptions { + protocol?: string; + auth?: string; + hostname?: string; + port?: string; + host?: string; + pathname?: string; + search?: string; + query?: any; + hash?: string; + path?: string; + } + + export function parse(urlStr: string, parseQueryString?: boolean , slashesDenoteHost?: boolean ): Url; + export function format(url: UrlOptions): string; + export function resolve(from: string, to: string): string; +} + +declare module "dns" { + export function lookup(domain: string, family: number, callback: (err: Error, address: string, family: number) =>void ): string; + export function lookup(domain: string, callback: (err: Error, address: string, family: number) =>void ): string; + export function resolve(domain: string, rrtype: string, callback: (err: Error, addresses: string[]) =>void ): string[]; + export function resolve(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; + export function resolve4(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; + export function resolve6(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; + export function resolveMx(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; + export function resolveTxt(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; + export function resolveSrv(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; + export function resolveNs(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; + export function resolveCname(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; + export function reverse(ip: string, callback: (err: Error, domains: string[]) =>void ): string[]; +} + +declare module "net" { + import stream = require("stream"); + + export interface Socket extends stream.Duplex { + // Extended base methods + write(buffer: Buffer): boolean; + write(buffer: Buffer, cb?: Function): boolean; + write(str: string, cb?: Function): boolean; + write(str: string, encoding?: string, cb?: Function): boolean; + write(str: string, encoding?: string, fd?: string): boolean; + + connect(port: number, host?: string, connectionListener?: Function): void; + connect(path: string, connectionListener?: Function): void; + bufferSize: number; + setEncoding(encoding?: string): void; + write(data: any, encoding?: string, callback?: Function): void; + destroy(): void; + pause(): void; + resume(): void; + setTimeout(timeout: number, callback?: Function): void; + setNoDelay(noDelay?: boolean): void; + setKeepAlive(enable?: boolean, initialDelay?: number): void; + address(): { port: number; family: string; address: string; }; + unref(): void; + ref(): void; + + remoteAddress: string; + remoteFamily: string; + remotePort: number; + localAddress: string; + localPort: number; + bytesRead: number; + bytesWritten: number; + + // Extended base methods + end(): void; + end(buffer: Buffer, cb?: Function): void; + end(str: string, cb?: Function): void; + end(str: string, encoding?: string, cb?: Function): void; + end(data?: any, encoding?: string): void; + } + + export var Socket: { + new (options?: { fd?: string; type?: string; allowHalfOpen?: boolean; }): Socket; + }; + + export interface Server extends Socket { + listen(port: number, host?: string, backlog?: number, listeningListener?: Function): Server; + listen(path: string, listeningListener?: Function): Server; + listen(handle: any, listeningListener?: Function): Server; + close(callback?: Function): Server; + address(): { port: number; family: string; address: string; }; + maxConnections: number; + connections: number; + } + export function createServer(connectionListener?: (socket: Socket) =>void ): Server; + export function createServer(options?: { allowHalfOpen?: boolean; }, connectionListener?: (socket: Socket) =>void ): Server; + export function connect(options: { allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; + export function connect(port: number, host?: string, connectionListener?: Function): Socket; + export function connect(path: string, connectionListener?: Function): Socket; + export function createConnection(options: { allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; + export function createConnection(port: number, host?: string, connectionListener?: Function): Socket; + export function createConnection(path: string, connectionListener?: Function): Socket; + export function isIP(input: string): number; + export function isIPv4(input: string): boolean; + export function isIPv6(input: string): boolean; +} + +declare module "dgram" { + import events = require("events"); + + interface RemoteInfo { + address: string; + port: number; + size: number; + } + + interface AddressInfo { + address: string; + family: string; + port: number; + } + + export function createSocket(type: string, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket; + + interface Socket extends events.EventEmitter { + send(buf: Buffer, offset: number, length: number, port: number, address: string, callback?: (error: Error, bytes: number) => void): void; + bind(port: number, address?: string, callback?: () => void): void; + close(): void; + address(): AddressInfo; + setBroadcast(flag: boolean): void; + setMulticastTTL(ttl: number): void; + setMulticastLoopback(flag: boolean): void; + addMembership(multicastAddress: string, multicastInterface?: string): void; + dropMembership(multicastAddress: string, multicastInterface?: string): void; + } +} + +declare module "fs" { + import stream = require("stream"); + import events = require("events"); + + interface Stats { + isFile(): boolean; + isDirectory(): boolean; + isBlockDevice(): boolean; + isCharacterDevice(): boolean; + isSymbolicLink(): boolean; + isFIFO(): boolean; + isSocket(): boolean; + dev: number; + ino: number; + mode: number; + nlink: number; + uid: number; + gid: number; + rdev: number; + size: number; + blksize: number; + blocks: number; + atime: Date; + mtime: Date; + ctime: Date; + } + + interface FSWatcher extends events.EventEmitter { + close(): void; + } + + export interface ReadStream extends stream.Readable { + close(): void; + } + export interface WriteStream extends stream.Writable { + close(): void; + } + + export function rename(oldPath: string, newPath: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function renameSync(oldPath: string, newPath: string): void; + export function truncate(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function truncate(path: string, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function truncateSync(path: string, len?: number): void; + export function ftruncate(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function ftruncate(fd: number, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function ftruncateSync(fd: number, len?: number): void; + export function chown(path: string, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function chownSync(path: string, uid: number, gid: number): void; + export function fchown(fd: number, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function fchownSync(fd: number, uid: number, gid: number): void; + export function lchown(path: string, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function lchownSync(path: string, uid: number, gid: number): void; + export function chmod(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function chmod(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function chmodSync(path: string, mode: number): void; + export function chmodSync(path: string, mode: string): void; + export function fchmod(fd: number, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function fchmod(fd: number, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function fchmodSync(fd: number, mode: number): void; + export function fchmodSync(fd: number, mode: string): void; + export function lchmod(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function lchmod(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function lchmodSync(path: string, mode: number): void; + export function lchmodSync(path: string, mode: string): void; + export function stat(path: string, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; + export function lstat(path: string, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; + export function fstat(fd: number, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; + export function statSync(path: string): Stats; + export function lstatSync(path: string): Stats; + export function fstatSync(fd: number): Stats; + export function link(srcpath: string, dstpath: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function linkSync(srcpath: string, dstpath: string): void; + export function symlink(srcpath: string, dstpath: string, type?: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function symlinkSync(srcpath: string, dstpath: string, type?: string): void; + export function readlink(path: string, callback?: (err: NodeJS.ErrnoException, linkString: string) => any): void; + export function readlinkSync(path: string): string; + export function realpath(path: string, callback?: (err: NodeJS.ErrnoException, resolvedPath: string) => any): void; + export function realpath(path: string, cache: {[path: string]: string}, callback: (err: NodeJS.ErrnoException, resolvedPath: string) =>any): void; + export function realpathSync(path: string, cache?: {[path: string]: string}): string; + export function unlink(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function unlinkSync(path: string): void; + export function rmdir(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function rmdirSync(path: string): void; + export function mkdir(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function mkdir(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function mkdir(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function mkdirSync(path: string, mode?: number): void; + export function mkdirSync(path: string, mode?: string): void; + export function readdir(path: string, callback?: (err: NodeJS.ErrnoException, files: string[]) => void): void; + export function readdirSync(path: string): string[]; + export function close(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function closeSync(fd: number): void; + export function open(path: string, flags: string, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; + export function open(path: string, flags: string, mode: number, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; + export function open(path: string, flags: string, mode: string, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; + export function openSync(path: string, flags: string, mode?: number): number; + export function openSync(path: string, flags: string, mode?: string): number; + export function utimes(path: string, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function utimes(path: string, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function utimesSync(path: string, atime: number, mtime: number): void; + export function utimesSync(path: string, atime: Date, mtime: Date): void; + export function futimes(fd: number, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function futimes(fd: number, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function futimesSync(fd: number, atime: number, mtime: number): void; + export function futimesSync(fd: number, atime: Date, mtime: Date): void; + export function fsync(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function fsyncSync(fd: number): void; + export function write(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, written: number, buffer: Buffer) => void): void; + export function writeSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number; + export function read(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, bytesRead: number, buffer: Buffer) => void): void; + export function readSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number; + export function readFile(filename: string, encoding: string, callback: (err: NodeJS.ErrnoException, data: string) => void): void; + export function readFile(filename: string, options: { encoding: string; flag?: string; }, callback: (err: NodeJS.ErrnoException, data: string) => void): void; + export function readFile(filename: string, options: { flag?: string; }, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; + export function readFile(filename: string, callback: (err: NodeJS.ErrnoException, data: Buffer) => void ): void; + export function readFileSync(filename: string, encoding: string): string; + export function readFileSync(filename: string, options: { encoding: string; flag?: string; }): string; + export function readFileSync(filename: string, options?: { flag?: string; }): Buffer; + export function writeFile(filename: string, data: any, callback?: (err: NodeJS.ErrnoException) => void): void; + export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; + export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; + export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; + export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void; + export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; + export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; + export function appendFile(filename: string, data: any, callback?: (err: NodeJS.ErrnoException) => void): void; + export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; + export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void; + export function watchFile(filename: string, listener: (curr: Stats, prev: Stats) => void): void; + export function watchFile(filename: string, options: { persistent?: boolean; interval?: number; }, listener: (curr: Stats, prev: Stats) => void): void; + export function unwatchFile(filename: string, listener?: (curr: Stats, prev: Stats) => void): void; + export function watch(filename: string, listener?: (event: string, filename: string) => any): FSWatcher; + export function watch(filename: string, options: { persistent?: boolean; }, listener?: (event: string, filename: string) => any): FSWatcher; + export function exists(path: string, callback?: (exists: boolean) => void): void; + export function existsSync(path: string): boolean; + export function createReadStream(path: string, options?: { + flags?: string; + encoding?: string; + fd?: string; + mode?: number; + bufferSize?: number; + }): ReadStream; + export function createReadStream(path: string, options?: { + flags?: string; + encoding?: string; + fd?: string; + mode?: string; + bufferSize?: number; + }): ReadStream; + export function createWriteStream(path: string, options?: { + flags?: string; + encoding?: string; + string?: string; + }): WriteStream; +} + +declare module "path" { + + export interface ParsedPath { + root: string; + dir: string; + base: string; + ext: string; + name: string; + } + + export function normalize(p: string): string; + export function join(...paths: any[]): string; + export function resolve(...pathSegments: any[]): string; + export function isAbsolute(p: string): boolean; + export function relative(from: string, to: string): string; + export function dirname(p: string): string; + export function basename(p: string, ext?: string): string; + export function extname(p: string): string; + export var sep: string; + export var delimiter: string; + export function parse(p: string): ParsedPath; + export function format(pP: ParsedPath): string; + + export module posix { + export function normalize(p: string): string; + export function join(...paths: any[]): string; + export function resolve(...pathSegments: any[]): string; + export function isAbsolute(p: string): boolean; + export function relative(from: string, to: string): string; + export function dirname(p: string): string; + export function basename(p: string, ext?: string): string; + export function extname(p: string): string; + export var sep: string; + export var delimiter: string; + export function parse(p: string): ParsedPath; + export function format(pP: ParsedPath): string; + } + + export module win32 { + export function normalize(p: string): string; + export function join(...paths: any[]): string; + export function resolve(...pathSegments: any[]): string; + export function isAbsolute(p: string): boolean; + export function relative(from: string, to: string): string; + export function dirname(p: string): string; + export function basename(p: string, ext?: string): string; + export function extname(p: string): string; + export var sep: string; + export var delimiter: string; + export function parse(p: string): ParsedPath; + export function format(pP: ParsedPath): string; + } +} + +declare module "string_decoder" { + export interface NodeStringDecoder { + write(buffer: Buffer): string; + detectIncompleteChar(buffer: Buffer): number; + } + export var StringDecoder: { + new (encoding: string): NodeStringDecoder; + }; +} + +declare module "tls" { + import crypto = require("crypto"); + import net = require("net"); + import stream = require("stream"); + + var CLIENT_RENEG_LIMIT: number; + var CLIENT_RENEG_WINDOW: number; + + export interface TlsOptions { + pfx?: any; //string or buffer + key?: any; //string or buffer + passphrase?: string; + cert?: any; + ca?: any; //string or buffer + crl?: any; //string or string array + ciphers?: string; + honorCipherOrder?: any; + requestCert?: boolean; + rejectUnauthorized?: boolean; + NPNProtocols?: any; //array or Buffer; + SNICallback?: (servername: string) => any; + } + + export interface ConnectionOptions { + host?: string; + port?: number; + socket?: net.Socket; + pfx?: any; //string | Buffer + key?: any; //string | Buffer + passphrase?: string; + cert?: any; //string | Buffer + ca?: any; //Array of string | Buffer + rejectUnauthorized?: boolean; + NPNProtocols?: any; //Array of string | Buffer + servername?: string; + } + + export interface Server extends net.Server { + // Extended base methods + listen(port: number, host?: string, backlog?: number, listeningListener?: Function): Server; + listen(path: string, listeningListener?: Function): Server; + listen(handle: any, listeningListener?: Function): Server; + + listen(port: number, host?: string, callback?: Function): Server; + close(): Server; + address(): { port: number; family: string; address: string; }; + addContext(hostName: string, credentials: { + key: string; + cert: string; + ca: string; + }): void; + maxConnections: number; + connections: number; + } + + export interface ClearTextStream extends stream.Duplex { + authorized: boolean; + authorizationError: Error; + getPeerCertificate(): any; + getCipher: { + name: string; + version: string; + }; + address: { + port: number; + family: string; + address: string; + }; + remoteAddress: string; + remotePort: number; + } + + export interface SecurePair { + encrypted: any; + cleartext: any; + } + + export function createServer(options: TlsOptions, secureConnectionListener?: (cleartextStream: ClearTextStream) =>void ): Server; + export function connect(options: TlsOptions, secureConnectionListener?: () =>void ): ClearTextStream; + export function connect(port: number, host?: string, options?: ConnectionOptions, secureConnectListener?: () =>void ): ClearTextStream; + export function connect(port: number, options?: ConnectionOptions, secureConnectListener?: () =>void ): ClearTextStream; + export function createSecurePair(credentials?: crypto.Credentials, isServer?: boolean, requestCert?: boolean, rejectUnauthorized?: boolean): SecurePair; +} + +declare module "crypto" { + export interface CredentialDetails { + pfx: string; + key: string; + passphrase: string; + cert: string; + ca: any; //string | string array + crl: any; //string | string array + ciphers: string; + } + export interface Credentials { context?: any; } + export function createCredentials(details: CredentialDetails): Credentials; + export function createHash(algorithm: string): Hash; + export function createHmac(algorithm: string, key: string): Hmac; + export function createHmac(algorithm: string, key: Buffer): Hmac; + interface Hash { + update(data: any, input_encoding?: string): Hash; + digest(encoding: 'buffer'): Buffer; + digest(encoding: string): any; + digest(): Buffer; + } + interface Hmac { + update(data: any, input_encoding?: string): Hmac; + digest(encoding: 'buffer'): Buffer; + digest(encoding: string): any; + digest(): Buffer; + } + export function createCipher(algorithm: string, password: any): Cipher; + export function createCipheriv(algorithm: string, key: any, iv: any): Cipher; + interface Cipher { + update(data: Buffer): Buffer; + update(data: string, input_encoding?: string, output_encoding?: string): string; + final(): Buffer; + final(output_encoding: string): string; + setAutoPadding(auto_padding: boolean): void; + } + export function createDecipher(algorithm: string, password: any): Decipher; + export function createDecipheriv(algorithm: string, key: any, iv: any): Decipher; + interface Decipher { + update(data: Buffer): Buffer; + update(data: string, input_encoding?: string, output_encoding?: string): string; + final(): Buffer; + final(output_encoding: string): string; + setAutoPadding(auto_padding: boolean): void; + } + export function createSign(algorithm: string): Signer; + interface Signer { + update(data: any): void; + sign(private_key: string, output_format: string): string; + } + export function createVerify(algorith: string): Verify; + interface Verify { + update(data: any): void; + verify(object: string, signature: string, signature_format?: string): boolean; + } + export function createDiffieHellman(prime_length: number): DiffieHellman; + export function createDiffieHellman(prime: number, encoding?: string): DiffieHellman; + interface DiffieHellman { + generateKeys(encoding?: string): string; + computeSecret(other_public_key: string, input_encoding?: string, output_encoding?: string): string; + getPrime(encoding?: string): string; + getGenerator(encoding: string): string; + getPublicKey(encoding?: string): string; + getPrivateKey(encoding?: string): string; + setPublicKey(public_key: string, encoding?: string): void; + setPrivateKey(public_key: string, encoding?: string): void; + } + export function getDiffieHellman(group_name: string): DiffieHellman; + export function pbkdf2(password: string, salt: string, iterations: number, keylen: number, callback: (err: Error, derivedKey: Buffer) => any): void; + export function pbkdf2Sync(password: string, salt: string, iterations: number, keylen: number) : Buffer; + export function randomBytes(size: number): Buffer; + export function randomBytes(size: number, callback: (err: Error, buf: Buffer) =>void ): void; + export function pseudoRandomBytes(size: number): Buffer; + export function pseudoRandomBytes(size: number, callback: (err: Error, buf: Buffer) =>void ): void; +} + +declare module "stream" { + import events = require("events"); + + export interface Stream extends events.EventEmitter { + pipe(destination: T, options?: { end?: boolean; }): T; + } + + export interface ReadableOptions { + highWaterMark?: number; + encoding?: string; + objectMode?: boolean; + } + + export class Readable extends events.EventEmitter implements NodeJS.ReadableStream { + readable: boolean; + constructor(opts?: ReadableOptions); + _read(size: number): void; + read(size?: number): string|Buffer; + setEncoding(encoding: string): void; + pause(): void; + resume(): void; + pipe(destination: T, options?: { end?: boolean; }): T; + unpipe(destination?: T): void; + unshift(chunk: string): void; + unshift(chunk: Buffer): void; + wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; + push(chunk: any, encoding?: string): boolean; + } + + export interface WritableOptions { + highWaterMark?: number; + decodeStrings?: boolean; + } + + export class Writable extends events.EventEmitter implements NodeJS.WritableStream { + writable: boolean; + constructor(opts?: WritableOptions); + _write(data: Buffer, encoding: string, callback: Function): void; + _write(data: string, encoding: string, callback: Function): void; + write(buffer: Buffer, cb?: Function): boolean; + write(str: string, cb?: Function): boolean; + write(str: string, encoding?: string, cb?: Function): boolean; + end(): void; + end(buffer: Buffer, cb?: Function): void; + end(str: string, cb?: Function): void; + end(str: string, encoding?: string, cb?: Function): void; + } + + export interface DuplexOptions extends ReadableOptions, WritableOptions { + allowHalfOpen?: boolean; + } + + // Note: Duplex extends both Readable and Writable. + export class Duplex extends Readable implements NodeJS.ReadWriteStream { + writable: boolean; + constructor(opts?: DuplexOptions); + _write(data: Buffer, encoding: string, callback: Function): void; + _write(data: string, encoding: string, callback: Function): void; + write(buffer: Buffer, cb?: Function): boolean; + write(str: string, cb?: Function): boolean; + write(str: string, encoding?: string, cb?: Function): boolean; + end(): void; + end(buffer: Buffer, cb?: Function): void; + end(str: string, cb?: Function): void; + end(str: string, encoding?: string, cb?: Function): void; + } + + export interface TransformOptions extends ReadableOptions, WritableOptions {} + + // Note: Transform lacks the _read and _write methods of Readable/Writable. + export class Transform extends events.EventEmitter implements NodeJS.ReadWriteStream { + readable: boolean; + writable: boolean; + constructor(opts?: TransformOptions); + _transform(chunk: Buffer, encoding: string, callback: Function): void; + _transform(chunk: string, encoding: string, callback: Function): void; + _flush(callback: Function): void; + read(size?: number): any; + setEncoding(encoding: string): void; + pause(): void; + resume(): void; + pipe(destination: T, options?: { end?: boolean; }): T; + unpipe(destination?: T): void; + unshift(chunk: string): void; + unshift(chunk: Buffer): void; + wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; + push(chunk: any, encoding?: string): boolean; + write(buffer: Buffer, cb?: Function): boolean; + write(str: string, cb?: Function): boolean; + write(str: string, encoding?: string, cb?: Function): boolean; + end(): void; + end(buffer: Buffer, cb?: Function): void; + end(str: string, cb?: Function): void; + end(str: string, encoding?: string, cb?: Function): void; + } + + export class PassThrough extends Transform {} +} + +declare module "util" { + export interface InspectOptions { + showHidden?: boolean; + depth?: number; + colors?: boolean; + customInspect?: boolean; + } + + export function format(format: any, ...param: any[]): string; + export function debug(string: string): void; + export function error(...param: any[]): void; + export function puts(...param: any[]): void; + export function print(...param: any[]): void; + export function log(string: string): void; + export function inspect(object: any, showHidden?: boolean, depth?: number, color?: boolean): string; + export function inspect(object: any, options: InspectOptions): string; + export function isArray(object: any): boolean; + export function isRegExp(object: any): boolean; + export function isDate(object: any): boolean; + export function isError(object: any): boolean; + export function inherits(constructor: any, superConstructor: any): void; +} + +declare module "assert" { + function internal (value: any, message?: string): void; + module internal { + export class AssertionError implements Error { + name: string; + message: string; + actual: any; + expected: any; + operator: string; + generatedMessage: boolean; + + constructor(options?: {message?: string; actual?: any; expected?: any; + operator?: string; stackStartFunction?: Function}); + } + + export function fail(actual?: any, expected?: any, message?: string, operator?: string): void; + export function ok(value: any, message?: string): void; + export function equal(actual: any, expected: any, message?: string): void; + export function notEqual(actual: any, expected: any, message?: string): void; + export function deepEqual(actual: any, expected: any, message?: string): void; + export function notDeepEqual(acutal: any, expected: any, message?: string): void; + export function strictEqual(actual: any, expected: any, message?: string): void; + export function notStrictEqual(actual: any, expected: any, message?: string): void; + export var throws: { + (block: Function, message?: string): void; + (block: Function, error: Function, message?: string): void; + (block: Function, error: RegExp, message?: string): void; + (block: Function, error: (err: any) => boolean, message?: string): void; + }; + + export var doesNotThrow: { + (block: Function, message?: string): void; + (block: Function, error: Function, message?: string): void; + (block: Function, error: RegExp, message?: string): void; + (block: Function, error: (err: any) => boolean, message?: string): void; + }; + + export function ifError(value: any): void; + } + + export = internal; +} + +declare module "tty" { + import net = require("net"); + + export function isatty(fd: number): boolean; + export interface ReadStream extends net.Socket { + isRaw: boolean; + setRawMode(mode: boolean): void; + } + export interface WriteStream extends net.Socket { + columns: number; + rows: number; + } +} + +declare module "domain" { + import events = require("events"); + + export class Domain extends events.EventEmitter { + run(fn: Function): void; + add(emitter: events.EventEmitter): void; + remove(emitter: events.EventEmitter): void; + bind(cb: (err: Error, data: any) => any): any; + intercept(cb: (data: any) => any): any; + dispose(): void; + + addListener(event: string, listener: Function): Domain; + on(event: string, listener: Function): Domain; + once(event: string, listener: Function): Domain; + removeListener(event: string, listener: Function): Domain; + removeAllListeners(event?: string): Domain; + } + + export function create(): Domain; +} From 89454008baa99a7932a888c430307a4bb3b8c8da Mon Sep 17 00:00:00 2001 From: Jon Ege Ronnenberg Date: Tue, 12 May 2015 21:12:17 +0000 Subject: [PATCH 26/33] get test to run on linux --- .settings/launch.json | 33 - .settings/settings.json | 5 - package.json | 2 +- test/malformed-dir.js | 2 + test/malformed.js | 4 +- test/public/d.js | 0 typings/node/node.d.ts | 1519 --------------------------------------- 7 files changed, 6 insertions(+), 1559 deletions(-) delete mode 100644 .settings/launch.json delete mode 100644 .settings/settings.json mode change 120000 => 100644 test/public/d.js delete mode 100644 typings/node/node.d.ts diff --git a/.settings/launch.json b/.settings/launch.json deleted file mode 100644 index 4b7de2c..0000000 --- a/.settings/launch.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "version": "0.1.0", - // List of configurations. Add new configurations or edit existing ones. - // ONLY "node" and "mono" are supported, change "type" to switch. - "configurations": [ - { - // Name of configuration; appears in the launch configuration drop down menu. - "name": "Launch app.js", - // Type of configuration. Possible values: "node", "mono". - "type": "node", - // Workspace relative or absolute path to the program. - "program": "./node_modules/.bin/tap", - // Automatically stop program after launch. - "stopOnEntry": true, - // Command line arguments passed to the program. - "args": [" ./test/custom-content-type-file-secret.js"], - // Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace. - "cwd": ".", - // Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH. - "runtimeExecutable": null, - // Environment variables passed to the program. - "env": { } - }, - { - "name": "Attach", - "type": "node", - // TCP/IP address. Default is "localhost". - "address": "localhost", - // Port to attach to. - "port": 5858 - } - ] -} diff --git a/.settings/settings.json b/.settings/settings.json deleted file mode 100644 index e234268..0000000 --- a/.settings/settings.json +++ /dev/null @@ -1,5 +0,0 @@ -// Place your settings in this file to overwrite default and user settings. -{ - "editor.insertSpaces": true, - "editor.tabSize": 2 -} \ No newline at end of file diff --git a/package.json b/package.json index 229422e..23513a7 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ }, "main": "./lib/ecstatic.js", "scripts": { - "test": "tap test/" + "test": "tap test/*.js" }, "bin": "./lib/ecstatic.js", "keywords": [ diff --git a/test/malformed-dir.js b/test/malformed-dir.js index 6ef24ab..0046318 100644 --- a/test/malformed-dir.js +++ b/test/malformed-dir.js @@ -5,6 +5,8 @@ var test = require('tap').test, test('malformed showdir uri', function (t) { var server = http.createServer(ecstatic(__dirname, { showDir: true })); + t.plan(1); + server.listen(0, function () { var r = http.get({ host: 'localhost', diff --git a/test/malformed.js b/test/malformed.js index 7a11f3b..a6bc985 100644 --- a/test/malformed.js +++ b/test/malformed.js @@ -3,7 +3,9 @@ var test = require('tap').test, http = require('http'); test('malformed uri', function (t) { - server = http.createServer(ecstatic(__dirname)); + var server = http.createServer(ecstatic(__dirname)); + + t.plan(1); server.listen(0, function () { var r = http.get({ diff --git a/test/public/d.js b/test/public/d.js deleted file mode 120000 index 7ab25e5..0000000 --- a/test/public/d.js +++ /dev/null @@ -1 +0,0 @@ -d.js diff --git a/test/public/d.js b/test/public/d.js new file mode 100644 index 0000000..7ab25e5 --- /dev/null +++ b/test/public/d.js @@ -0,0 +1 @@ +d.js diff --git a/typings/node/node.d.ts b/typings/node/node.d.ts deleted file mode 100644 index b0a7b77..0000000 --- a/typings/node/node.d.ts +++ /dev/null @@ -1,1519 +0,0 @@ -// Type definitions for Node.js v0.12.0 -// Project: http://nodejs.org/ -// Definitions by: Microsoft TypeScript , DefinitelyTyped -// Definitions: https://github.com/borisyankov/DefinitelyTyped - -/************************************************ -* * -* Node.js v0.12.0 API * -* * -************************************************/ - -/************************************************ -* * -* GLOBAL * -* * -************************************************/ -declare var process: NodeJS.Process; -declare var global: NodeJS.Global; - -declare var __filename: string; -declare var __dirname: string; - -declare function setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer; -declare function clearTimeout(timeoutId: NodeJS.Timer): void; -declare function setInterval(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer; -declare function clearInterval(intervalId: NodeJS.Timer): void; -declare function setImmediate(callback: (...args: any[]) => void, ...args: any[]): any; -declare function clearImmediate(immediateId: any): void; - -declare var require: { - (id: string): any; - resolve(id:string): string; - cache: any; - extensions: any; - main: any; -}; - -declare var module: { - exports: any; - require(id: string): any; - id: string; - filename: string; - loaded: boolean; - parent: any; - children: any[]; -}; - -// Same as module.exports -declare var exports: any; -declare var SlowBuffer: { - new (str: string, encoding?: string): Buffer; - new (size: number): Buffer; - new (size: Uint8Array): Buffer; - new (array: any[]): Buffer; - prototype: Buffer; - isBuffer(obj: any): boolean; - byteLength(string: string, encoding?: string): number; - concat(list: Buffer[], totalLength?: number): Buffer; -}; - - -// Buffer class -interface Buffer extends NodeBuffer {} -declare var Buffer: { - new (str: string, encoding?: string): Buffer; - new (size: number): Buffer; - new (size: Uint8Array): Buffer; - new (array: any[]): Buffer; - prototype: Buffer; - isBuffer(obj: any): boolean; - byteLength(string: string, encoding?: string): number; - concat(list: Buffer[], totalLength?: number): Buffer; -}; - -/************************************************ -* * -* GLOBAL INTERFACES * -* * -************************************************/ -declare module NodeJS { - export interface ErrnoException extends Error { - errno?: number; - code?: string; - path?: string; - syscall?: string; - } - - export interface EventEmitter { - addListener(event: string, listener: Function): EventEmitter; - on(event: string, listener: Function): EventEmitter; - once(event: string, listener: Function): EventEmitter; - removeListener(event: string, listener: Function): EventEmitter; - removeAllListeners(event?: string): EventEmitter; - setMaxListeners(n: number): void; - listeners(event: string): Function[]; - emit(event: string, ...args: any[]): boolean; - } - - export interface ReadableStream extends EventEmitter { - readable: boolean; - read(size?: number): string|Buffer; - setEncoding(encoding: string): void; - pause(): void; - resume(): void; - pipe(destination: T, options?: { end?: boolean; }): T; - unpipe(destination?: T): void; - unshift(chunk: string): void; - unshift(chunk: Buffer): void; - wrap(oldStream: ReadableStream): ReadableStream; - } - - export interface WritableStream extends EventEmitter { - writable: boolean; - write(buffer: Buffer, cb?: Function): boolean; - write(str: string, cb?: Function): boolean; - write(str: string, encoding?: string, cb?: Function): boolean; - end(): void; - end(buffer: Buffer, cb?: Function): void; - end(str: string, cb?: Function): void; - end(str: string, encoding?: string, cb?: Function): void; - } - - export interface ReadWriteStream extends ReadableStream, WritableStream {} - - export interface Process extends EventEmitter { - stdout: WritableStream; - stderr: WritableStream; - stdin: ReadableStream; - argv: string[]; - execPath: string; - abort(): void; - chdir(directory: string): void; - cwd(): string; - env: any; - exit(code?: number): void; - getgid(): number; - setgid(id: number): void; - setgid(id: string): void; - getuid(): number; - setuid(id: number): void; - setuid(id: string): void; - version: string; - versions: { - http_parser: string; - node: string; - v8: string; - ares: string; - uv: string; - zlib: string; - openssl: string; - }; - config: { - target_defaults: { - cflags: any[]; - default_configuration: string; - defines: string[]; - include_dirs: string[]; - libraries: string[]; - }; - variables: { - clang: number; - host_arch: string; - node_install_npm: boolean; - node_install_waf: boolean; - node_prefix: string; - node_shared_openssl: boolean; - node_shared_v8: boolean; - node_shared_zlib: boolean; - node_use_dtrace: boolean; - node_use_etw: boolean; - node_use_openssl: boolean; - target_arch: string; - v8_no_strict_aliasing: number; - v8_use_snapshot: boolean; - visibility: string; - }; - }; - kill(pid: number, signal?: string): void; - pid: number; - title: string; - arch: string; - platform: string; - memoryUsage(): { rss: number; heapTotal: number; heapUsed: number; }; - nextTick(callback: Function): void; - umask(mask?: number): number; - uptime(): number; - hrtime(time?:number[]): number[]; - - // Worker - send?(message: any, sendHandle?: any): void; - } - - export interface Global { - Array: typeof Array; - ArrayBuffer: typeof ArrayBuffer; - Boolean: typeof Boolean; - Buffer: typeof Buffer; - DataView: typeof DataView; - Date: typeof Date; - Error: typeof Error; - EvalError: typeof EvalError; - Float32Array: typeof Float32Array; - Float64Array: typeof Float64Array; - Function: typeof Function; - GLOBAL: Global; - Infinity: typeof Infinity; - Int16Array: typeof Int16Array; - Int32Array: typeof Int32Array; - Int8Array: typeof Int8Array; - Intl: typeof Intl; - JSON: typeof JSON; - Map: typeof Map; - Math: typeof Math; - NaN: typeof NaN; - Number: typeof Number; - Object: typeof Object; - Promise: Function; - RangeError: typeof RangeError; - ReferenceError: typeof ReferenceError; - RegExp: typeof RegExp; - Set: typeof Set; - String: typeof String; - Symbol: Function; - SyntaxError: typeof SyntaxError; - TypeError: typeof TypeError; - URIError: typeof URIError; - Uint16Array: typeof Uint16Array; - Uint32Array: typeof Uint32Array; - Uint8Array: typeof Uint8Array; - Uint8ClampedArray: Function; - WeakMap: typeof WeakMap; - WeakSet: Function; - clearImmediate: (immediateId: any) => void; - clearInterval: (intervalId: NodeJS.Timer) => void; - clearTimeout: (timeoutId: NodeJS.Timer) => void; - console: typeof console; - decodeURI: typeof decodeURI; - decodeURIComponent: typeof decodeURIComponent; - encodeURI: typeof encodeURI; - encodeURIComponent: typeof encodeURIComponent; - escape: (str: string) => string; - eval: typeof eval; - global: Global; - isFinite: typeof isFinite; - isNaN: typeof isNaN; - parseFloat: typeof parseFloat; - parseInt: typeof parseInt; - process: Process; - root: Global; - setImmediate: (callback: (...args: any[]) => void, ...args: any[]) => any; - setInterval: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => NodeJS.Timer; - setTimeout: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => NodeJS.Timer; - undefined: typeof undefined; - unescape: (str: string) => string; - } - - export interface Timer { - ref() : void; - unref() : void; - } -} - -/** - * @deprecated - */ -interface NodeBuffer { - [index: number]: number; - write(string: string, offset?: number, length?: number, encoding?: string): number; - toString(encoding?: string, start?: number, end?: number): string; - toJSON(): any; - length: number; - copy(targetBuffer: Buffer, targetStart?: number, sourceStart?: number, sourceEnd?: number): number; - slice(start?: number, end?: number): Buffer; - readUInt8(offset: number, noAsset?: boolean): number; - readUInt16LE(offset: number, noAssert?: boolean): number; - readUInt16BE(offset: number, noAssert?: boolean): number; - readUInt32LE(offset: number, noAssert?: boolean): number; - readUInt32BE(offset: number, noAssert?: boolean): number; - readInt8(offset: number, noAssert?: boolean): number; - readInt16LE(offset: number, noAssert?: boolean): number; - readInt16BE(offset: number, noAssert?: boolean): number; - readInt32LE(offset: number, noAssert?: boolean): number; - readInt32BE(offset: number, noAssert?: boolean): number; - readFloatLE(offset: number, noAssert?: boolean): number; - readFloatBE(offset: number, noAssert?: boolean): number; - readDoubleLE(offset: number, noAssert?: boolean): number; - readDoubleBE(offset: number, noAssert?: boolean): number; - writeUInt8(value: number, offset: number, noAssert?: boolean): void; - writeUInt16LE(value: number, offset: number, noAssert?: boolean): void; - writeUInt16BE(value: number, offset: number, noAssert?: boolean): void; - writeUInt32LE(value: number, offset: number, noAssert?: boolean): void; - writeUInt32BE(value: number, offset: number, noAssert?: boolean): void; - writeInt8(value: number, offset: number, noAssert?: boolean): void; - writeInt16LE(value: number, offset: number, noAssert?: boolean): void; - writeInt16BE(value: number, offset: number, noAssert?: boolean): void; - writeInt32LE(value: number, offset: number, noAssert?: boolean): void; - writeInt32BE(value: number, offset: number, noAssert?: boolean): void; - writeFloatLE(value: number, offset: number, noAssert?: boolean): void; - writeFloatBE(value: number, offset: number, noAssert?: boolean): void; - writeDoubleLE(value: number, offset: number, noAssert?: boolean): void; - writeDoubleBE(value: number, offset: number, noAssert?: boolean): void; - fill(value: any, offset?: number, end?: number): void; -} - -/************************************************ -* * -* MODULES * -* * -************************************************/ -declare module "buffer" { - export var INSPECT_MAX_BYTES: number; -} - -declare module "querystring" { - export function stringify(obj: any, sep?: string, eq?: string): string; - export function parse(str: string, sep?: string, eq?: string, options?: { maxKeys?: number; }): any; - export function escape(str: string): string; - export function unescape(str: string): string; -} - -declare module "events" { - export class EventEmitter implements NodeJS.EventEmitter { - static listenerCount(emitter: EventEmitter, event: string): number; - - addListener(event: string, listener: Function): EventEmitter; - on(event: string, listener: Function): EventEmitter; - once(event: string, listener: Function): EventEmitter; - removeListener(event: string, listener: Function): EventEmitter; - removeAllListeners(event?: string): EventEmitter; - setMaxListeners(n: number): void; - listeners(event: string): Function[]; - emit(event: string, ...args: any[]): boolean; - } -} - -declare module "http" { - import events = require("events"); - import net = require("net"); - import stream = require("stream"); - - export interface Server extends events.EventEmitter { - listen(port: number, hostname?: string, backlog?: number, callback?: Function): Server; - listen(port: number, hostname?: string, callback?: Function): Server; - listen(path: string, callback?: Function): Server; - listen(handle: any, listeningListener?: Function): Server; - close(cb?: any): Server; - address(): { port: number; family: string; address: string; }; - maxHeadersCount: number; - } - /** - * @deprecated Use IncomingMessage - */ - export interface ServerRequest extends IncomingMessage { - connection: net.Socket; - } - export interface ServerResponse extends events.EventEmitter, stream.Writable { - // Extended base methods - write(buffer: Buffer): boolean; - write(buffer: Buffer, cb?: Function): boolean; - write(str: string, cb?: Function): boolean; - write(str: string, encoding?: string, cb?: Function): boolean; - write(str: string, encoding?: string, fd?: string): boolean; - - writeContinue(): void; - writeHead(statusCode: number, reasonPhrase?: string, headers?: any): void; - writeHead(statusCode: number, headers?: any): void; - statusCode: number; - setHeader(name: string, value: string): void; - sendDate: boolean; - getHeader(name: string): string; - removeHeader(name: string): void; - write(chunk: any, encoding?: string): any; - addTrailers(headers: any): void; - - // Extended base methods - end(): void; - end(buffer: Buffer, cb?: Function): void; - end(str: string, cb?: Function): void; - end(str: string, encoding?: string, cb?: Function): void; - end(data?: any, encoding?: string): void; - } - export interface ClientRequest extends events.EventEmitter, stream.Writable { - // Extended base methods - write(buffer: Buffer): boolean; - write(buffer: Buffer, cb?: Function): boolean; - write(str: string, cb?: Function): boolean; - write(str: string, encoding?: string, cb?: Function): boolean; - write(str: string, encoding?: string, fd?: string): boolean; - - write(chunk: any, encoding?: string): void; - abort(): void; - setTimeout(timeout: number, callback?: Function): void; - setNoDelay(noDelay?: boolean): void; - setSocketKeepAlive(enable?: boolean, initialDelay?: number): void; - - // Extended base methods - end(): void; - end(buffer: Buffer, cb?: Function): void; - end(str: string, cb?: Function): void; - end(str: string, encoding?: string, cb?: Function): void; - end(data?: any, encoding?: string): void; - } - export interface IncomingMessage extends events.EventEmitter, stream.Readable { - httpVersion: string; - headers: any; - rawHeaders: string[]; - trailers: any; - rawTrailers: any; - setTimeout(msecs: number, callback: Function): NodeJS.Timer; - /** - * Only valid for request obtained from http.Server. - */ - method?: string; - /** - * Only valid for request obtained from http.Server. - */ - url?: string; - /** - * Only valid for response obtained from http.ClientRequest. - */ - statusCode?: number; - /** - * Only valid for response obtained from http.ClientRequest. - */ - statusMessage?: string; - socket: net.Socket; - } - /** - * @deprecated Use IncomingMessage - */ - export interface ClientResponse extends IncomingMessage { } - - export interface AgentOptions { - /** - * Keep sockets around in a pool to be used by other requests in the future. Default = false - */ - keepAlive?: boolean; - /** - * When using HTTP KeepAlive, how often to send TCP KeepAlive packets over sockets being kept alive. Default = 1000. - * Only relevant if keepAlive is set to true. - */ - keepAliveMsecs?: number; - /** - * Maximum number of sockets to allow per host. Default for Node 0.10 is 5, default for Node 0.12 is Infinity - */ - maxSockets?: number; - /** - * Maximum number of sockets to leave open in a free state. Only relevant if keepAlive is set to true. Default = 256. - */ - maxFreeSockets?: number; - } - - export class Agent { - maxSockets: number; - sockets: any; - requests: any; - - constructor(opts?: AgentOptions); - - /** - * Destroy any sockets that are currently in use by the agent. - * It is usually not necessary to do this. However, if you are using an agent with KeepAlive enabled, - * then it is best to explicitly shut down the agent when you know that it will no longer be used. Otherwise, - * sockets may hang open for quite a long time before the server terminates them. - */ - destroy(): void; - } - - export var STATUS_CODES: { - [errorCode: number]: string; - [errorCode: string]: string; - }; - export function createServer(requestListener?: (request: IncomingMessage, response: ServerResponse) =>void ): Server; - export function createClient(port?: number, host?: string): any; - export function request(options: any, callback?: (res: IncomingMessage) => void): ClientRequest; - export function get(options: any, callback?: (res: IncomingMessage) => void): ClientRequest; - export var globalAgent: Agent; -} - -declare module "cluster" { - import child = require("child_process"); - import events = require("events"); - - export interface ClusterSettings { - exec?: string; - args?: string[]; - silent?: boolean; - } - - export class Worker extends events.EventEmitter { - id: string; - process: child.ChildProcess; - suicide: boolean; - send(message: any, sendHandle?: any): void; - kill(signal?: string): void; - destroy(signal?: string): void; - disconnect(): void; - } - - export var settings: ClusterSettings; - export var isMaster: boolean; - export var isWorker: boolean; - export function setupMaster(settings?: ClusterSettings): void; - export function fork(env?: any): Worker; - export function disconnect(callback?: Function): void; - export var worker: Worker; - export var workers: Worker[]; - - // Event emitter - export function addListener(event: string, listener: Function): void; - export function on(event: string, listener: Function): any; - export function once(event: string, listener: Function): void; - export function removeListener(event: string, listener: Function): void; - export function removeAllListeners(event?: string): void; - export function setMaxListeners(n: number): void; - export function listeners(event: string): Function[]; - export function emit(event: string, ...args: any[]): boolean; -} - -declare module "zlib" { - import stream = require("stream"); - export interface ZlibOptions { chunkSize?: number; windowBits?: number; level?: number; memLevel?: number; strategy?: number; dictionary?: any; } - - export interface Gzip extends stream.Transform { } - export interface Gunzip extends stream.Transform { } - export interface Deflate extends stream.Transform { } - export interface Inflate extends stream.Transform { } - export interface DeflateRaw extends stream.Transform { } - export interface InflateRaw extends stream.Transform { } - export interface Unzip extends stream.Transform { } - - export function createGzip(options?: ZlibOptions): Gzip; - export function createGunzip(options?: ZlibOptions): Gunzip; - export function createDeflate(options?: ZlibOptions): Deflate; - export function createInflate(options?: ZlibOptions): Inflate; - export function createDeflateRaw(options?: ZlibOptions): DeflateRaw; - export function createInflateRaw(options?: ZlibOptions): InflateRaw; - export function createUnzip(options?: ZlibOptions): Unzip; - - export function deflate(buf: Buffer, callback: (error: Error, result: any) =>void ): void; - export function deflateRaw(buf: Buffer, callback: (error: Error, result: any) =>void ): void; - export function gzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; - export function gunzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; - export function inflate(buf: Buffer, callback: (error: Error, result: any) =>void ): void; - export function inflateRaw(buf: Buffer, callback: (error: Error, result: any) =>void ): void; - export function unzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; - - // Constants - export var Z_NO_FLUSH: number; - export var Z_PARTIAL_FLUSH: number; - export var Z_SYNC_FLUSH: number; - export var Z_FULL_FLUSH: number; - export var Z_FINISH: number; - export var Z_BLOCK: number; - export var Z_TREES: number; - export var Z_OK: number; - export var Z_STREAM_END: number; - export var Z_NEED_DICT: number; - export var Z_ERRNO: number; - export var Z_STREAM_ERROR: number; - export var Z_DATA_ERROR: number; - export var Z_MEM_ERROR: number; - export var Z_BUF_ERROR: number; - export var Z_VERSION_ERROR: number; - export var Z_NO_COMPRESSION: number; - export var Z_BEST_SPEED: number; - export var Z_BEST_COMPRESSION: number; - export var Z_DEFAULT_COMPRESSION: number; - export var Z_FILTERED: number; - export var Z_HUFFMAN_ONLY: number; - export var Z_RLE: number; - export var Z_FIXED: number; - export var Z_DEFAULT_STRATEGY: number; - export var Z_BINARY: number; - export var Z_TEXT: number; - export var Z_ASCII: number; - export var Z_UNKNOWN: number; - export var Z_DEFLATED: number; - export var Z_NULL: number; -} - -declare module "os" { - export function tmpdir(): string; - export function hostname(): string; - export function type(): string; - export function platform(): string; - export function arch(): string; - export function release(): string; - export function uptime(): number; - export function loadavg(): number[]; - export function totalmem(): number; - export function freemem(): number; - export function cpus(): { model: string; speed: number; times: { user: number; nice: number; sys: number; idle: number; irq: number; }; }[]; - export function networkInterfaces(): any; - export var EOL: string; -} - -declare module "https" { - import tls = require("tls"); - import events = require("events"); - import http = require("http"); - - export interface ServerOptions { - pfx?: any; - key?: any; - passphrase?: string; - cert?: any; - ca?: any; - crl?: any; - ciphers?: string; - honorCipherOrder?: boolean; - requestCert?: boolean; - rejectUnauthorized?: boolean; - NPNProtocols?: any; - SNICallback?: (servername: string) => any; - } - - export interface RequestOptions { - host?: string; - hostname?: string; - port?: number; - path?: string; - method?: string; - headers?: any; - auth?: string; - agent?: any; - pfx?: any; - key?: any; - passphrase?: string; - cert?: any; - ca?: any; - ciphers?: string; - rejectUnauthorized?: boolean; - } - - export interface Agent { - maxSockets: number; - sockets: any; - requests: any; - } - export var Agent: { - new (options?: RequestOptions): Agent; - }; - export interface Server extends tls.Server { } - export function createServer(options: ServerOptions, requestListener?: Function): Server; - export function request(options: RequestOptions, callback?: (res: http.IncomingMessage) =>void ): http.ClientRequest; - export function get(options: RequestOptions, callback?: (res: http.IncomingMessage) =>void ): http.ClientRequest; - export var globalAgent: Agent; -} - -declare module "punycode" { - export function decode(string: string): string; - export function encode(string: string): string; - export function toUnicode(domain: string): string; - export function toASCII(domain: string): string; - export var ucs2: ucs2; - interface ucs2 { - decode(string: string): string; - encode(codePoints: number[]): string; - } - export var version: any; -} - -declare module "repl" { - import stream = require("stream"); - import events = require("events"); - - export interface ReplOptions { - prompt?: string; - input?: NodeJS.ReadableStream; - output?: NodeJS.WritableStream; - terminal?: boolean; - eval?: Function; - useColors?: boolean; - useGlobal?: boolean; - ignoreUndefined?: boolean; - writer?: Function; - } - export function start(options: ReplOptions): events.EventEmitter; -} - -declare module "readline" { - import events = require("events"); - import stream = require("stream"); - - export interface ReadLine extends events.EventEmitter { - setPrompt(prompt: string, length: number): void; - prompt(preserveCursor?: boolean): void; - question(query: string, callback: Function): void; - pause(): void; - resume(): void; - close(): void; - write(data: any, key?: any): void; - } - export interface ReadLineOptions { - input: NodeJS.ReadableStream; - output: NodeJS.WritableStream; - completer?: Function; - terminal?: boolean; - } - export function createInterface(options: ReadLineOptions): ReadLine; -} - -declare module "vm" { - export interface Context { } - export interface Script { - runInThisContext(): void; - runInNewContext(sandbox?: Context): void; - } - export function runInThisContext(code: string, filename?: string): void; - export function runInNewContext(code: string, sandbox?: Context, filename?: string): void; - export function runInContext(code: string, context: Context, filename?: string): void; - export function createContext(initSandbox?: Context): Context; - export function createScript(code: string, filename?: string): Script; -} - -declare module "child_process" { - import events = require("events"); - import stream = require("stream"); - - export interface ChildProcess extends events.EventEmitter { - stdin: stream.Writable; - stdout: stream.Readable; - stderr: stream.Readable; - pid: number; - kill(signal?: string): void; - send(message: any, sendHandle?: any): void; - disconnect(): void; - } - - export function spawn(command: string, args?: string[], options?: { - cwd?: string; - stdio?: any; - custom?: any; - env?: any; - detached?: boolean; - }): ChildProcess; - export function exec(command: string, options: { - cwd?: string; - stdio?: any; - customFds?: any; - env?: any; - encoding?: string; - timeout?: number; - maxBuffer?: number; - killSignal?: string; - }, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; - export function exec(command: string, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; - export function execFile(file: string, - callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; - export function execFile(file: string, args?: string[], - callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; - export function execFile(file: string, args?: string[], options?: { - cwd?: string; - stdio?: any; - customFds?: any; - env?: any; - encoding?: string; - timeout?: number; - maxBuffer?: string; - killSignal?: string; - }, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; - export function fork(modulePath: string, args?: string[], options?: { - cwd?: string; - env?: any; - encoding?: string; - }): ChildProcess; - export function execSync(command: string, options?: { - cwd?: string; - input?: string|Buffer; - stdio?: any; - env?: any; - uid?: number; - gid?: number; - timeout?: number; - maxBuffer?: number; - killSignal?: string; - encoding?: string; - }): ChildProcess; - export function execFileSync(command: string, args?: string[], options?: { - cwd?: string; - input?: string|Buffer; - stdio?: any; - env?: any; - uid?: number; - gid?: number; - timeout?: number; - maxBuffer?: number; - killSignal?: string; - encoding?: string; - }): ChildProcess; -} - -declare module "url" { - export interface Url { - href: string; - protocol: string; - auth: string; - hostname: string; - port: string; - host: string; - pathname: string; - search: string; - query: any; // string | Object - slashes: boolean; - hash?: string; - path?: string; - } - - export interface UrlOptions { - protocol?: string; - auth?: string; - hostname?: string; - port?: string; - host?: string; - pathname?: string; - search?: string; - query?: any; - hash?: string; - path?: string; - } - - export function parse(urlStr: string, parseQueryString?: boolean , slashesDenoteHost?: boolean ): Url; - export function format(url: UrlOptions): string; - export function resolve(from: string, to: string): string; -} - -declare module "dns" { - export function lookup(domain: string, family: number, callback: (err: Error, address: string, family: number) =>void ): string; - export function lookup(domain: string, callback: (err: Error, address: string, family: number) =>void ): string; - export function resolve(domain: string, rrtype: string, callback: (err: Error, addresses: string[]) =>void ): string[]; - export function resolve(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; - export function resolve4(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; - export function resolve6(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; - export function resolveMx(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; - export function resolveTxt(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; - export function resolveSrv(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; - export function resolveNs(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; - export function resolveCname(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; - export function reverse(ip: string, callback: (err: Error, domains: string[]) =>void ): string[]; -} - -declare module "net" { - import stream = require("stream"); - - export interface Socket extends stream.Duplex { - // Extended base methods - write(buffer: Buffer): boolean; - write(buffer: Buffer, cb?: Function): boolean; - write(str: string, cb?: Function): boolean; - write(str: string, encoding?: string, cb?: Function): boolean; - write(str: string, encoding?: string, fd?: string): boolean; - - connect(port: number, host?: string, connectionListener?: Function): void; - connect(path: string, connectionListener?: Function): void; - bufferSize: number; - setEncoding(encoding?: string): void; - write(data: any, encoding?: string, callback?: Function): void; - destroy(): void; - pause(): void; - resume(): void; - setTimeout(timeout: number, callback?: Function): void; - setNoDelay(noDelay?: boolean): void; - setKeepAlive(enable?: boolean, initialDelay?: number): void; - address(): { port: number; family: string; address: string; }; - unref(): void; - ref(): void; - - remoteAddress: string; - remoteFamily: string; - remotePort: number; - localAddress: string; - localPort: number; - bytesRead: number; - bytesWritten: number; - - // Extended base methods - end(): void; - end(buffer: Buffer, cb?: Function): void; - end(str: string, cb?: Function): void; - end(str: string, encoding?: string, cb?: Function): void; - end(data?: any, encoding?: string): void; - } - - export var Socket: { - new (options?: { fd?: string; type?: string; allowHalfOpen?: boolean; }): Socket; - }; - - export interface Server extends Socket { - listen(port: number, host?: string, backlog?: number, listeningListener?: Function): Server; - listen(path: string, listeningListener?: Function): Server; - listen(handle: any, listeningListener?: Function): Server; - close(callback?: Function): Server; - address(): { port: number; family: string; address: string; }; - maxConnections: number; - connections: number; - } - export function createServer(connectionListener?: (socket: Socket) =>void ): Server; - export function createServer(options?: { allowHalfOpen?: boolean; }, connectionListener?: (socket: Socket) =>void ): Server; - export function connect(options: { allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; - export function connect(port: number, host?: string, connectionListener?: Function): Socket; - export function connect(path: string, connectionListener?: Function): Socket; - export function createConnection(options: { allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; - export function createConnection(port: number, host?: string, connectionListener?: Function): Socket; - export function createConnection(path: string, connectionListener?: Function): Socket; - export function isIP(input: string): number; - export function isIPv4(input: string): boolean; - export function isIPv6(input: string): boolean; -} - -declare module "dgram" { - import events = require("events"); - - interface RemoteInfo { - address: string; - port: number; - size: number; - } - - interface AddressInfo { - address: string; - family: string; - port: number; - } - - export function createSocket(type: string, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket; - - interface Socket extends events.EventEmitter { - send(buf: Buffer, offset: number, length: number, port: number, address: string, callback?: (error: Error, bytes: number) => void): void; - bind(port: number, address?: string, callback?: () => void): void; - close(): void; - address(): AddressInfo; - setBroadcast(flag: boolean): void; - setMulticastTTL(ttl: number): void; - setMulticastLoopback(flag: boolean): void; - addMembership(multicastAddress: string, multicastInterface?: string): void; - dropMembership(multicastAddress: string, multicastInterface?: string): void; - } -} - -declare module "fs" { - import stream = require("stream"); - import events = require("events"); - - interface Stats { - isFile(): boolean; - isDirectory(): boolean; - isBlockDevice(): boolean; - isCharacterDevice(): boolean; - isSymbolicLink(): boolean; - isFIFO(): boolean; - isSocket(): boolean; - dev: number; - ino: number; - mode: number; - nlink: number; - uid: number; - gid: number; - rdev: number; - size: number; - blksize: number; - blocks: number; - atime: Date; - mtime: Date; - ctime: Date; - } - - interface FSWatcher extends events.EventEmitter { - close(): void; - } - - export interface ReadStream extends stream.Readable { - close(): void; - } - export interface WriteStream extends stream.Writable { - close(): void; - } - - export function rename(oldPath: string, newPath: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function renameSync(oldPath: string, newPath: string): void; - export function truncate(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function truncate(path: string, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function truncateSync(path: string, len?: number): void; - export function ftruncate(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function ftruncate(fd: number, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function ftruncateSync(fd: number, len?: number): void; - export function chown(path: string, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function chownSync(path: string, uid: number, gid: number): void; - export function fchown(fd: number, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function fchownSync(fd: number, uid: number, gid: number): void; - export function lchown(path: string, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function lchownSync(path: string, uid: number, gid: number): void; - export function chmod(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function chmod(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function chmodSync(path: string, mode: number): void; - export function chmodSync(path: string, mode: string): void; - export function fchmod(fd: number, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function fchmod(fd: number, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function fchmodSync(fd: number, mode: number): void; - export function fchmodSync(fd: number, mode: string): void; - export function lchmod(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function lchmod(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function lchmodSync(path: string, mode: number): void; - export function lchmodSync(path: string, mode: string): void; - export function stat(path: string, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; - export function lstat(path: string, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; - export function fstat(fd: number, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; - export function statSync(path: string): Stats; - export function lstatSync(path: string): Stats; - export function fstatSync(fd: number): Stats; - export function link(srcpath: string, dstpath: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function linkSync(srcpath: string, dstpath: string): void; - export function symlink(srcpath: string, dstpath: string, type?: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function symlinkSync(srcpath: string, dstpath: string, type?: string): void; - export function readlink(path: string, callback?: (err: NodeJS.ErrnoException, linkString: string) => any): void; - export function readlinkSync(path: string): string; - export function realpath(path: string, callback?: (err: NodeJS.ErrnoException, resolvedPath: string) => any): void; - export function realpath(path: string, cache: {[path: string]: string}, callback: (err: NodeJS.ErrnoException, resolvedPath: string) =>any): void; - export function realpathSync(path: string, cache?: {[path: string]: string}): string; - export function unlink(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function unlinkSync(path: string): void; - export function rmdir(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function rmdirSync(path: string): void; - export function mkdir(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function mkdir(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function mkdir(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function mkdirSync(path: string, mode?: number): void; - export function mkdirSync(path: string, mode?: string): void; - export function readdir(path: string, callback?: (err: NodeJS.ErrnoException, files: string[]) => void): void; - export function readdirSync(path: string): string[]; - export function close(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function closeSync(fd: number): void; - export function open(path: string, flags: string, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; - export function open(path: string, flags: string, mode: number, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; - export function open(path: string, flags: string, mode: string, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; - export function openSync(path: string, flags: string, mode?: number): number; - export function openSync(path: string, flags: string, mode?: string): number; - export function utimes(path: string, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function utimes(path: string, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function utimesSync(path: string, atime: number, mtime: number): void; - export function utimesSync(path: string, atime: Date, mtime: Date): void; - export function futimes(fd: number, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function futimes(fd: number, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function futimesSync(fd: number, atime: number, mtime: number): void; - export function futimesSync(fd: number, atime: Date, mtime: Date): void; - export function fsync(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function fsyncSync(fd: number): void; - export function write(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, written: number, buffer: Buffer) => void): void; - export function writeSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number; - export function read(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, bytesRead: number, buffer: Buffer) => void): void; - export function readSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number; - export function readFile(filename: string, encoding: string, callback: (err: NodeJS.ErrnoException, data: string) => void): void; - export function readFile(filename: string, options: { encoding: string; flag?: string; }, callback: (err: NodeJS.ErrnoException, data: string) => void): void; - export function readFile(filename: string, options: { flag?: string; }, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; - export function readFile(filename: string, callback: (err: NodeJS.ErrnoException, data: Buffer) => void ): void; - export function readFileSync(filename: string, encoding: string): string; - export function readFileSync(filename: string, options: { encoding: string; flag?: string; }): string; - export function readFileSync(filename: string, options?: { flag?: string; }): Buffer; - export function writeFile(filename: string, data: any, callback?: (err: NodeJS.ErrnoException) => void): void; - export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; - export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; - export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; - export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void; - export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; - export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; - export function appendFile(filename: string, data: any, callback?: (err: NodeJS.ErrnoException) => void): void; - export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; - export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void; - export function watchFile(filename: string, listener: (curr: Stats, prev: Stats) => void): void; - export function watchFile(filename: string, options: { persistent?: boolean; interval?: number; }, listener: (curr: Stats, prev: Stats) => void): void; - export function unwatchFile(filename: string, listener?: (curr: Stats, prev: Stats) => void): void; - export function watch(filename: string, listener?: (event: string, filename: string) => any): FSWatcher; - export function watch(filename: string, options: { persistent?: boolean; }, listener?: (event: string, filename: string) => any): FSWatcher; - export function exists(path: string, callback?: (exists: boolean) => void): void; - export function existsSync(path: string): boolean; - export function createReadStream(path: string, options?: { - flags?: string; - encoding?: string; - fd?: string; - mode?: number; - bufferSize?: number; - }): ReadStream; - export function createReadStream(path: string, options?: { - flags?: string; - encoding?: string; - fd?: string; - mode?: string; - bufferSize?: number; - }): ReadStream; - export function createWriteStream(path: string, options?: { - flags?: string; - encoding?: string; - string?: string; - }): WriteStream; -} - -declare module "path" { - - export interface ParsedPath { - root: string; - dir: string; - base: string; - ext: string; - name: string; - } - - export function normalize(p: string): string; - export function join(...paths: any[]): string; - export function resolve(...pathSegments: any[]): string; - export function isAbsolute(p: string): boolean; - export function relative(from: string, to: string): string; - export function dirname(p: string): string; - export function basename(p: string, ext?: string): string; - export function extname(p: string): string; - export var sep: string; - export var delimiter: string; - export function parse(p: string): ParsedPath; - export function format(pP: ParsedPath): string; - - export module posix { - export function normalize(p: string): string; - export function join(...paths: any[]): string; - export function resolve(...pathSegments: any[]): string; - export function isAbsolute(p: string): boolean; - export function relative(from: string, to: string): string; - export function dirname(p: string): string; - export function basename(p: string, ext?: string): string; - export function extname(p: string): string; - export var sep: string; - export var delimiter: string; - export function parse(p: string): ParsedPath; - export function format(pP: ParsedPath): string; - } - - export module win32 { - export function normalize(p: string): string; - export function join(...paths: any[]): string; - export function resolve(...pathSegments: any[]): string; - export function isAbsolute(p: string): boolean; - export function relative(from: string, to: string): string; - export function dirname(p: string): string; - export function basename(p: string, ext?: string): string; - export function extname(p: string): string; - export var sep: string; - export var delimiter: string; - export function parse(p: string): ParsedPath; - export function format(pP: ParsedPath): string; - } -} - -declare module "string_decoder" { - export interface NodeStringDecoder { - write(buffer: Buffer): string; - detectIncompleteChar(buffer: Buffer): number; - } - export var StringDecoder: { - new (encoding: string): NodeStringDecoder; - }; -} - -declare module "tls" { - import crypto = require("crypto"); - import net = require("net"); - import stream = require("stream"); - - var CLIENT_RENEG_LIMIT: number; - var CLIENT_RENEG_WINDOW: number; - - export interface TlsOptions { - pfx?: any; //string or buffer - key?: any; //string or buffer - passphrase?: string; - cert?: any; - ca?: any; //string or buffer - crl?: any; //string or string array - ciphers?: string; - honorCipherOrder?: any; - requestCert?: boolean; - rejectUnauthorized?: boolean; - NPNProtocols?: any; //array or Buffer; - SNICallback?: (servername: string) => any; - } - - export interface ConnectionOptions { - host?: string; - port?: number; - socket?: net.Socket; - pfx?: any; //string | Buffer - key?: any; //string | Buffer - passphrase?: string; - cert?: any; //string | Buffer - ca?: any; //Array of string | Buffer - rejectUnauthorized?: boolean; - NPNProtocols?: any; //Array of string | Buffer - servername?: string; - } - - export interface Server extends net.Server { - // Extended base methods - listen(port: number, host?: string, backlog?: number, listeningListener?: Function): Server; - listen(path: string, listeningListener?: Function): Server; - listen(handle: any, listeningListener?: Function): Server; - - listen(port: number, host?: string, callback?: Function): Server; - close(): Server; - address(): { port: number; family: string; address: string; }; - addContext(hostName: string, credentials: { - key: string; - cert: string; - ca: string; - }): void; - maxConnections: number; - connections: number; - } - - export interface ClearTextStream extends stream.Duplex { - authorized: boolean; - authorizationError: Error; - getPeerCertificate(): any; - getCipher: { - name: string; - version: string; - }; - address: { - port: number; - family: string; - address: string; - }; - remoteAddress: string; - remotePort: number; - } - - export interface SecurePair { - encrypted: any; - cleartext: any; - } - - export function createServer(options: TlsOptions, secureConnectionListener?: (cleartextStream: ClearTextStream) =>void ): Server; - export function connect(options: TlsOptions, secureConnectionListener?: () =>void ): ClearTextStream; - export function connect(port: number, host?: string, options?: ConnectionOptions, secureConnectListener?: () =>void ): ClearTextStream; - export function connect(port: number, options?: ConnectionOptions, secureConnectListener?: () =>void ): ClearTextStream; - export function createSecurePair(credentials?: crypto.Credentials, isServer?: boolean, requestCert?: boolean, rejectUnauthorized?: boolean): SecurePair; -} - -declare module "crypto" { - export interface CredentialDetails { - pfx: string; - key: string; - passphrase: string; - cert: string; - ca: any; //string | string array - crl: any; //string | string array - ciphers: string; - } - export interface Credentials { context?: any; } - export function createCredentials(details: CredentialDetails): Credentials; - export function createHash(algorithm: string): Hash; - export function createHmac(algorithm: string, key: string): Hmac; - export function createHmac(algorithm: string, key: Buffer): Hmac; - interface Hash { - update(data: any, input_encoding?: string): Hash; - digest(encoding: 'buffer'): Buffer; - digest(encoding: string): any; - digest(): Buffer; - } - interface Hmac { - update(data: any, input_encoding?: string): Hmac; - digest(encoding: 'buffer'): Buffer; - digest(encoding: string): any; - digest(): Buffer; - } - export function createCipher(algorithm: string, password: any): Cipher; - export function createCipheriv(algorithm: string, key: any, iv: any): Cipher; - interface Cipher { - update(data: Buffer): Buffer; - update(data: string, input_encoding?: string, output_encoding?: string): string; - final(): Buffer; - final(output_encoding: string): string; - setAutoPadding(auto_padding: boolean): void; - } - export function createDecipher(algorithm: string, password: any): Decipher; - export function createDecipheriv(algorithm: string, key: any, iv: any): Decipher; - interface Decipher { - update(data: Buffer): Buffer; - update(data: string, input_encoding?: string, output_encoding?: string): string; - final(): Buffer; - final(output_encoding: string): string; - setAutoPadding(auto_padding: boolean): void; - } - export function createSign(algorithm: string): Signer; - interface Signer { - update(data: any): void; - sign(private_key: string, output_format: string): string; - } - export function createVerify(algorith: string): Verify; - interface Verify { - update(data: any): void; - verify(object: string, signature: string, signature_format?: string): boolean; - } - export function createDiffieHellman(prime_length: number): DiffieHellman; - export function createDiffieHellman(prime: number, encoding?: string): DiffieHellman; - interface DiffieHellman { - generateKeys(encoding?: string): string; - computeSecret(other_public_key: string, input_encoding?: string, output_encoding?: string): string; - getPrime(encoding?: string): string; - getGenerator(encoding: string): string; - getPublicKey(encoding?: string): string; - getPrivateKey(encoding?: string): string; - setPublicKey(public_key: string, encoding?: string): void; - setPrivateKey(public_key: string, encoding?: string): void; - } - export function getDiffieHellman(group_name: string): DiffieHellman; - export function pbkdf2(password: string, salt: string, iterations: number, keylen: number, callback: (err: Error, derivedKey: Buffer) => any): void; - export function pbkdf2Sync(password: string, salt: string, iterations: number, keylen: number) : Buffer; - export function randomBytes(size: number): Buffer; - export function randomBytes(size: number, callback: (err: Error, buf: Buffer) =>void ): void; - export function pseudoRandomBytes(size: number): Buffer; - export function pseudoRandomBytes(size: number, callback: (err: Error, buf: Buffer) =>void ): void; -} - -declare module "stream" { - import events = require("events"); - - export interface Stream extends events.EventEmitter { - pipe(destination: T, options?: { end?: boolean; }): T; - } - - export interface ReadableOptions { - highWaterMark?: number; - encoding?: string; - objectMode?: boolean; - } - - export class Readable extends events.EventEmitter implements NodeJS.ReadableStream { - readable: boolean; - constructor(opts?: ReadableOptions); - _read(size: number): void; - read(size?: number): string|Buffer; - setEncoding(encoding: string): void; - pause(): void; - resume(): void; - pipe(destination: T, options?: { end?: boolean; }): T; - unpipe(destination?: T): void; - unshift(chunk: string): void; - unshift(chunk: Buffer): void; - wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; - push(chunk: any, encoding?: string): boolean; - } - - export interface WritableOptions { - highWaterMark?: number; - decodeStrings?: boolean; - } - - export class Writable extends events.EventEmitter implements NodeJS.WritableStream { - writable: boolean; - constructor(opts?: WritableOptions); - _write(data: Buffer, encoding: string, callback: Function): void; - _write(data: string, encoding: string, callback: Function): void; - write(buffer: Buffer, cb?: Function): boolean; - write(str: string, cb?: Function): boolean; - write(str: string, encoding?: string, cb?: Function): boolean; - end(): void; - end(buffer: Buffer, cb?: Function): void; - end(str: string, cb?: Function): void; - end(str: string, encoding?: string, cb?: Function): void; - } - - export interface DuplexOptions extends ReadableOptions, WritableOptions { - allowHalfOpen?: boolean; - } - - // Note: Duplex extends both Readable and Writable. - export class Duplex extends Readable implements NodeJS.ReadWriteStream { - writable: boolean; - constructor(opts?: DuplexOptions); - _write(data: Buffer, encoding: string, callback: Function): void; - _write(data: string, encoding: string, callback: Function): void; - write(buffer: Buffer, cb?: Function): boolean; - write(str: string, cb?: Function): boolean; - write(str: string, encoding?: string, cb?: Function): boolean; - end(): void; - end(buffer: Buffer, cb?: Function): void; - end(str: string, cb?: Function): void; - end(str: string, encoding?: string, cb?: Function): void; - } - - export interface TransformOptions extends ReadableOptions, WritableOptions {} - - // Note: Transform lacks the _read and _write methods of Readable/Writable. - export class Transform extends events.EventEmitter implements NodeJS.ReadWriteStream { - readable: boolean; - writable: boolean; - constructor(opts?: TransformOptions); - _transform(chunk: Buffer, encoding: string, callback: Function): void; - _transform(chunk: string, encoding: string, callback: Function): void; - _flush(callback: Function): void; - read(size?: number): any; - setEncoding(encoding: string): void; - pause(): void; - resume(): void; - pipe(destination: T, options?: { end?: boolean; }): T; - unpipe(destination?: T): void; - unshift(chunk: string): void; - unshift(chunk: Buffer): void; - wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; - push(chunk: any, encoding?: string): boolean; - write(buffer: Buffer, cb?: Function): boolean; - write(str: string, cb?: Function): boolean; - write(str: string, encoding?: string, cb?: Function): boolean; - end(): void; - end(buffer: Buffer, cb?: Function): void; - end(str: string, cb?: Function): void; - end(str: string, encoding?: string, cb?: Function): void; - } - - export class PassThrough extends Transform {} -} - -declare module "util" { - export interface InspectOptions { - showHidden?: boolean; - depth?: number; - colors?: boolean; - customInspect?: boolean; - } - - export function format(format: any, ...param: any[]): string; - export function debug(string: string): void; - export function error(...param: any[]): void; - export function puts(...param: any[]): void; - export function print(...param: any[]): void; - export function log(string: string): void; - export function inspect(object: any, showHidden?: boolean, depth?: number, color?: boolean): string; - export function inspect(object: any, options: InspectOptions): string; - export function isArray(object: any): boolean; - export function isRegExp(object: any): boolean; - export function isDate(object: any): boolean; - export function isError(object: any): boolean; - export function inherits(constructor: any, superConstructor: any): void; -} - -declare module "assert" { - function internal (value: any, message?: string): void; - module internal { - export class AssertionError implements Error { - name: string; - message: string; - actual: any; - expected: any; - operator: string; - generatedMessage: boolean; - - constructor(options?: {message?: string; actual?: any; expected?: any; - operator?: string; stackStartFunction?: Function}); - } - - export function fail(actual?: any, expected?: any, message?: string, operator?: string): void; - export function ok(value: any, message?: string): void; - export function equal(actual: any, expected: any, message?: string): void; - export function notEqual(actual: any, expected: any, message?: string): void; - export function deepEqual(actual: any, expected: any, message?: string): void; - export function notDeepEqual(acutal: any, expected: any, message?: string): void; - export function strictEqual(actual: any, expected: any, message?: string): void; - export function notStrictEqual(actual: any, expected: any, message?: string): void; - export var throws: { - (block: Function, message?: string): void; - (block: Function, error: Function, message?: string): void; - (block: Function, error: RegExp, message?: string): void; - (block: Function, error: (err: any) => boolean, message?: string): void; - }; - - export var doesNotThrow: { - (block: Function, message?: string): void; - (block: Function, error: Function, message?: string): void; - (block: Function, error: RegExp, message?: string): void; - (block: Function, error: (err: any) => boolean, message?: string): void; - }; - - export function ifError(value: any): void; - } - - export = internal; -} - -declare module "tty" { - import net = require("net"); - - export function isatty(fd: number): boolean; - export interface ReadStream extends net.Socket { - isRaw: boolean; - setRawMode(mode: boolean): void; - } - export interface WriteStream extends net.Socket { - columns: number; - rows: number; - } -} - -declare module "domain" { - import events = require("events"); - - export class Domain extends events.EventEmitter { - run(fn: Function): void; - add(emitter: events.EventEmitter): void; - remove(emitter: events.EventEmitter): void; - bind(cb: (err: Error, data: any) => any): any; - intercept(cb: (data: any) => any): any; - dispose(): void; - - addListener(event: string, listener: Function): Domain; - on(event: string, listener: Function): Domain; - once(event: string, listener: Function): Domain; - removeListener(event: string, listener: Function): Domain; - removeAllListeners(event?: string): Domain; - } - - export function create(): Domain; -} From a68034581a9371ccc86c65070083d3ec4d506c0d Mon Sep 17 00:00:00 2001 From: Jon Ege Ronnenberg Date: Tue, 12 May 2015 22:20:40 +0000 Subject: [PATCH 27/33] pass the malformed tests on linux --- test/malformed-dir.js | 15 +++++++-------- test/malformed.js | 13 +++++-------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/test/malformed-dir.js b/test/malformed-dir.js index 0046318..594cec9 100644 --- a/test/malformed-dir.js +++ b/test/malformed-dir.js @@ -1,21 +1,20 @@ var test = require('tap').test, ecstatic = require('../lib/ecstatic'), - http = require('http'); + http = require('http'), + request = require('request'); test('malformed showdir uri', function (t) { var server = http.createServer(ecstatic(__dirname, { showDir: true })); - t.plan(1); + t.plan(2); server.listen(0, function () { - var r = http.get({ - host: 'localhost', - port: server.address().port, - path: '/?%' - }); - r.on('response', function (res) { + + request.get('http://localhost:' + server.address().port + '/?%', function (err, res, body) { + t.ifError(err); t.equal(res.statusCode, 400); server.close(function() { t.end(); }); }); + }); }); diff --git a/test/malformed.js b/test/malformed.js index a6bc985..05639aa 100644 --- a/test/malformed.js +++ b/test/malformed.js @@ -1,19 +1,16 @@ var test = require('tap').test, ecstatic = require('../lib/ecstatic'), - http = require('http'); + http = require('http'), + request = require('request'); test('malformed uri', function (t) { var server = http.createServer(ecstatic(__dirname)); - t.plan(1); + t.plan(2); server.listen(0, function () { - var r = http.get({ - host: 'localhost', - port: server.address().port, - path: '/%' - }); - r.on('response', function (res) { + request.get('http://localhost:' + server.address().port + '/%', function (err, res, body) { + t.ifError(err); t.equal(res.statusCode, 400); server.close(function() { t.end(); }); }); From b0ac06efddfe4e603a77a014fba6831ac459578b Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Wed, 13 May 2015 00:29:21 +0200 Subject: [PATCH 28/33] finish going through all of the unit tests --- ChangeLog.md | 7 +++++-- package.json | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 317910e..6e6b7e3 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,8 +1,11 @@ +2015/05/13 Version 0.8.2 +- Updated dev depedencies and fixed all failing tests + 2015/05/12 Version 0.8.1 -- Fixed an issue where .types file is in another directory that the root directory. +- Fixed an issue where .types file is in another directory that the root directory 2015/05/11 Version 0.8.0 -- Add ability to define custom mime-types, inline or with Apache .types file. +- Add ability to define custom mime-types, inline or with Apache .types file 2015/05/09 Version 0.7.6 - Fix double encoding in directory listings diff --git a/package.json b/package.json index 23513a7..92923d0 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Joshua Holbrook (http://jesusabdullah.net)", "name": "ecstatic", "description": "A simple static file server middleware that works with both Express and Flatiron", - "version": "0.8.1", + "version": "0.8.2", "homepage": "https://github.com/jfhbrook/node-ecstatic", "repository": { "type": "git", From 367152ca4828a222abce747bb9ba30dc1dcd33bc Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Wed, 13 May 2015 00:38:13 +0200 Subject: [PATCH 29/33] testing isaacs/node-tap#128 on travis --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 92923d0..c9fd01c 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ }, "main": "./lib/ecstatic.js", "scripts": { - "test": "tap test/*.js" + "test": "tap test/" }, "bin": "./lib/ecstatic.js", "keywords": [ From d03c691f692d34af918cdcf18ebf2774473b36b5 Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Wed, 13 May 2015 00:50:57 +0200 Subject: [PATCH 30/33] cleanup --- package.json | 2 +- test/custom-content-type-file-secret.js | 9 --------- test/custom-content-type-file.js | 9 --------- test/mime.js | 4 ++-- test/public/custom_mime_type.opml | 18 +++++++++--------- 5 files changed, 12 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index c9fd01c..92923d0 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ }, "main": "./lib/ecstatic.js", "scripts": { - "test": "tap test/" + "test": "tap test/*.js" }, "bin": "./lib/ecstatic.js", "keywords": [ diff --git a/test/custom-content-type-file-secret.js b/test/custom-content-type-file-secret.js index deb9bfc..ab0d14c 100644 --- a/test/custom-content-type-file-secret.js +++ b/test/custom-content-type-file-secret.js @@ -26,12 +26,3 @@ test('custom contentType via .types file', function(t) { }); }); }); - -// test('server teardown', function (t) { -// server.close(function() { t.end(); }); - -// var to = setTimeout(function () { -// process.stderr.write('# server not closing; slaughtering process.\n'); -// process.exit(0); -// }, 5000); -// }); diff --git a/test/custom-content-type-file.js b/test/custom-content-type-file.js index a24d064..1a972f5 100644 --- a/test/custom-content-type-file.js +++ b/test/custom-content-type-file.js @@ -43,12 +43,3 @@ test('custom contentType via .types file', function(t) { }); }); }); - -// test('server teardown', function (t) { -// server.close(function() { t.end(); }); - -// var to = setTimeout(function () { -// process.stderr.write('# server not closing; slaughtering process.\n'); -// process.exit(0); -// }, 5000); -// }); diff --git a/test/mime.js b/test/mime.js index 9130623..6950985 100644 --- a/test/mime.js +++ b/test/mime.js @@ -1,5 +1,5 @@ var test = require('tap').test, - mime = require('mime'); + mime = require('mime'); test('mime package lookup', function(t) { t.plan(4); @@ -35,7 +35,7 @@ test('custom definition of mime-type with a .types file', function(t) { t.equal(mime.lookup('.opml'), 'application/foo'); // see public/custom_mime_type.types - t.throws( mime.load.bind(mime, 'public/this_file_does_not_exist.types') ); + t.throws( mime.load.bind(mime, 'public/this_file_does_not_exist.types') ); t.end(); }); diff --git a/test/public/custom_mime_type.opml b/test/public/custom_mime_type.opml index 53f3582..5e24bcc 100644 --- a/test/public/custom_mime_type.opml +++ b/test/public/custom_mime_type.opml @@ -1,13 +1,13 @@ - - Tue 9 May 2006 06:44:27 GMT+00:00 - BKN - Sat 20 May 2006 00:17:25 GMT+00:00 - - - - - + + Tue 9 May 2006 06:44:27 GMT+00:00 + BKN + Sat 20 May 2006 00:17:25 GMT+00:00 + + + + + From 51414b23ed38e93f95fb3d443cf2aa8b44e5e55a Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Wed, 13 May 2015 13:47:53 +0200 Subject: [PATCH 31/33] cleanup functional test and removed side effects (creation of weird folders that wasn't used for anything) --- test/union-multiple-folders.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/union-multiple-folders.js b/test/union-multiple-folders.js index db2dbe8..bb90c06 100644 --- a/test/union-multiple-folders.js +++ b/test/union-multiple-folders.js @@ -1,17 +1,15 @@ +'use strict'; + var test = require('tap').test, ecstatic = require('../lib/ecstatic'), union = require('union'), request = require('request'), - mkdirp = require('mkdirp'), - fs = require('fs'), path = require('path'), eol = require('eol'); var subdir = __dirname + '/public/subdir', - anotherSubdir = __dirname + '/public/another-subdir', - baseDir = 'base'; - -mkdirp.sync(root + '/emptyDir'); + anotherSubdir = __dirname + '/public/another-subdir', + baseDir = 'base'; var cases = require('./secret/union-multiple-folders-cases'); @@ -43,6 +41,9 @@ test('union', function(t) { server.listen(port, function() { var pending = filenames.length; + + t.plan(pending * 3); + filenames.forEach(function(file) { var uri = 'http://localhost:' + port + path.join('/', baseDir, file), headers = cases[file].headers || {}; From 1b49d5de96d516934a3acf654206a61c3242277c Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Wed, 13 May 2015 13:49:51 +0200 Subject: [PATCH 32/33] @jfhbrook what do you think about the handleError option? Should we not throw if it is true? --- lib/ecstatic.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ecstatic.js b/lib/ecstatic.js index abe1dee..f3149a3 100755 --- a/lib/ecstatic.js +++ b/lib/ecstatic.js @@ -34,6 +34,7 @@ var ecstatic = module.exports = function (dir, options) { // Support hashes and .types files in mimeTypes @since 0.8 if (opts.mimeTypes) { if (typeof opts.mimeTypes === 'string') { + //TODO: should handleError have any effect here? mime.load(opts.mimeTypes); // will throw if path is wrong as intended } else if (typeof opts.mimeTypes === 'object') { mime.define(opts.mimeTypes); From 4356c6e0d264b06aae8737af3df901198ca758fa Mon Sep 17 00:00:00 2001 From: dotnetcarpenter Date: Wed, 13 May 2015 14:05:54 +0200 Subject: [PATCH 33/33] lets speed things up and prepare for ecma6 --- lib/ecstatic.js | 2 ++ lib/ecstatic/opts.js | 2 ++ lib/ecstatic/showdir.js | 2 ++ lib/ecstatic/status-handlers.js | 2 ++ 4 files changed, 8 insertions(+) diff --git a/lib/ecstatic.js b/lib/ecstatic.js index f3149a3..ff06913 100755 --- a/lib/ecstatic.js +++ b/lib/ecstatic.js @@ -1,5 +1,7 @@ #! /usr/bin/env node +'use strict'; + var path = require('path'), fs = require('fs'), url = require('url'), diff --git a/lib/ecstatic/opts.js b/lib/ecstatic/opts.js index 77d78a8..3159bbd 100644 --- a/lib/ecstatic/opts.js +++ b/lib/ecstatic/opts.js @@ -1,5 +1,7 @@ // This is so you can have options aliasing and defaults in one place. +'use strict'; + module.exports = function (opts) { var autoIndex = true, diff --git a/lib/ecstatic/showdir.js b/lib/ecstatic/showdir.js index 731a323..5943b24 100644 --- a/lib/ecstatic/showdir.js +++ b/lib/ecstatic/showdir.js @@ -1,3 +1,5 @@ +'use strict'; + var ecstatic = require('../ecstatic'), fs = require('fs'), path = require('path'), diff --git a/lib/ecstatic/status-handlers.js b/lib/ecstatic/status-handlers.js index 9874534..8fcefcf 100644 --- a/lib/ecstatic/status-handlers.js +++ b/lib/ecstatic/status-handlers.js @@ -1,3 +1,5 @@ +'use strict'; + // not modified exports['304'] = function (res, next) { res.statusCode = 304;