Skip to content

Commit 160743b

Browse files
committed
Improve performance + new behaviour disable-middleware
1 parent fad892b commit 160743b

5 files changed

Lines changed: 67 additions & 12 deletions

File tree

changes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ BETA ======= 1.9.0
5959
- added: configs directory
6060
- added: F.behaviour(url, flags);
6161
- added: behaviour: disable-upload-dimension (default: false)
62+
- added: behaviour: disable-middleware (default: false)
6263

6364
- updated: (IMPORTANT) routing: `json` flag is not required for receiving incomming data as JSON
6465
- updated: `F.mail(address, subject, view, [model], [callback], [language])` added language

index.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ function Framework() {
228228

229229
this.id = null;
230230
this.version = 1900;
231-
this.version_header = '1.9.0-18';
231+
this.version_header = '1.9.0-19';
232232

233233
var version = process.version.toString().replace('v', '').replace(/\./g, '');
234234
if (version[1] === '0')
@@ -5239,7 +5239,7 @@ Framework.prototype.listener = function(req, res) {
52395239
}
52405240
}
52415241

5242-
req.uri = parser.parse(protocol + '://' + req.host + req.url);
5242+
req.uri = framework_internal.parseURI(protocol, req.host, req.url);
52435243
req.path = framework_internal.routeSplit(req.uri.pathname);
52445244
req.body = {};
52455245
req.files = new Array(0);
@@ -5251,16 +5251,12 @@ Framework.prototype.listener = function(req, res) {
52515251
res.success = false;
52525252
res.setHeader('X-Powered-By', 'total.js v' + self.version_header);
52535253

5254-
if (framework._request_check_mobile)
5255-
req.mobile = REG_MOBILE.test(req.headers['user-agent']);
5256-
52575254
if (self.isDebug)
52585255
res.setHeader('Mode', 'debug');
52595256

5260-
req.isStaticFile = framework.config['allow-handle-static-files'] ? utils.isStaticFile(req.uri.pathname) : false;
5257+
req.isStaticFile = framework.config['allow-handle-static-files'] ? framework_utils.isStaticFile(req.uri.pathname) : false;
52615258

52625259
var can = true;
5263-
52645260
if (req.isStaticFile) {
52655261
req.extension = path.extname(req.uri.pathname).substring(1);
52665262
switch (req.extension) {
@@ -5284,6 +5280,9 @@ Framework.prototype.listener = function(req, res) {
52845280
if (self._length_request_middleware === 0)
52855281
return self._request_continue(req, res, headers, protocol);
52865282

5283+
if (!req.can('disable-middleware'))
5284+
return self._request_continue(req, res, headers, protocol);
5285+
52875286
var func = new Array(self._length_request_middleware);
52885287
var indexer = 0;
52895288

@@ -5523,7 +5522,7 @@ Framework.prototype._upgrade = function(req, socket, head) {
55235522
}
55245523
}
55255524

5526-
req.uri = parser.parse((req.connection.encrypted || headers['x-forwarded-protocol'] === 'https' || headers['x-forwarded-protocol'] === 'wss' ? 'wss' : 'ws') + '://' + req.headers.host + req.url);
5525+
req.uri = framework_internal.parseURI((req.connection.encrypted || headers['x-forwarded-protocol'] === 'https' || headers['x-forwarded-protocol'] === 'wss' ? 'wss' : 'ws'), req.headers.host, req.url);
55275526
req.session = null;
55285527
req.user = null;
55295528
req.flags = [req.isSecure ? 'https' : 'http', 'get'];
@@ -5540,6 +5539,9 @@ Framework.prototype._upgrade = function(req, socket, head) {
55405539
if (self._length_request_middleware === 0)
55415540
return self._upgrade_prepare(req, path, headers);
55425541

5542+
if (!req.can('disable-middleware'))
5543+
return self._request_continue(req, res, headers, protocol);
5544+
55435545
var func = new Array(self._length_request_middleware);
55445546
var indexer = 0;
55455547

@@ -6068,7 +6070,6 @@ Framework.prototype.testing = function(stop, callback) {
60686070
};
60696071

60706072
var options = parser.parse((test.url.indexOf('http://') > 0 || test.url.indexOf('https://') > 0 ? '' : 'http://' + self.ip + ':' + self.port) + test.url);
6071-
60726073
if (typeof(test.data) === TYPE_FUNCTION)
60736074
test.data = test.data();
60746075

@@ -8656,6 +8657,11 @@ Subscribe.prototype.doEndfile = function() {
86568657
var req = self.req;
86578658
var res = self.res;
86588659

8660+
if (!framework._length_files) {
8661+
framework.responseStatic(self.req, self.res);
8662+
return;
8663+
}
8664+
86598665
for (var i = 0; i < framework._length_files; i++) {
86608666
var file = framework.routes.files[i];
86618667
try {
@@ -13477,6 +13483,12 @@ http.IncomingMessage.prototype = {
1347713483
return this.$language;
1347813484
},
1347913485

13486+
get mobile() {
13487+
if (this.$mobile === undefined)
13488+
this.$mobile = REG_MOBILE.test(this.headers['user-agent']);
13489+
return this.$mobile;
13490+
},
13491+
1348013492
set language(value) {
1348113493
this.$language = value;
1348213494
}

internal.js

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ exports.parseMULTIPART = function(req, contentType, route, tmpDirectory, subscri
174174

175175
var wh = null;
176176

177-
if (req.can('disable-upload-dimension')) {
177+
if (req.can('disable-measuring')) {
178178
switch (tmp.type) {
179179
case 'image/jpeg':
180180
wh = framework_image.measureJPG(buffer.slice(start));
@@ -2899,6 +2899,47 @@ exports.appendModel = function(str) {
28992899
return str.substring(0, index) + '(model' + (end[0] === ')' ? end : ',' + end);
29002900
};
29012901

2902+
exports.parseURI = function(protocol, host, url) {
2903+
2904+
var port = host.lastIndexOf(':');
2905+
var hostname;
2906+
var search = url.indexOf('?');
2907+
var pathname;
2908+
var query = null;
2909+
2910+
if (port === -1) {
2911+
port = null;
2912+
hostname = host;
2913+
} else {
2914+
hostname = host.substring(0, port);
2915+
port = host.substring(port + 1);
2916+
}
2917+
2918+
if (search === -1) {
2919+
search = null;
2920+
pathname = url;
2921+
} else {
2922+
pathname = url.substring(0, search);
2923+
search = url.substring(search);
2924+
query = search.substring(1);
2925+
}
2926+
2927+
return {
2928+
auth: null,
2929+
hash: null,
2930+
host: host,
2931+
hostname: hostname,
2932+
href: protocol + '://' + host + url,
2933+
path: url,
2934+
pathname: pathname,
2935+
port: host.substring(host.lastIndexOf(':') + 1),
2936+
protocol: protocol + ':',
2937+
query: query,
2938+
search: search,
2939+
slashes: true
2940+
};
2941+
};
2942+
29022943
/**
29032944
* Destroy the stream
29042945
* @param {Stream} stream

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"scripts": {
5858
"test": "echo \"Error: no test specified\" && exit 1"
5959
},
60-
"version": "1.9.0-18",
60+
"version": "1.9.0-19",
6161
"homepage": "http://www.totaljs.com",
6262
"bugs": {
6363
"url": "https://github.com/totaljs/framework/issues",

test/controllers/default.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ function view_homepage() {
271271
console.log(this.hash('sha1', '123456', false));
272272

273273
//this.view('homepage');
274-
this.plain(this.framework.usage(true));
274+
this.plain(framework.usage(true));
275275
}
276276

277277
function view_layout() {
@@ -566,6 +566,7 @@ function viewViews() {
566566
assert.ok(output.contains('<link rel="dns-prefetch" href="//fonts.googleapis.com" />'), name + 'dns');
567567
assert.ok(output.contains('<link rel="prefetch" href="http://daker.me/2013/05/hello-world.html" />'), name + 'prefetch');
568568
assert.ok(output.contains('<link rel="prerender" href="http://daker.me/2013/05/hello-world.html" />'), name + 'prerender');
569+
569570
assert.ok(output.contains('<link rel="canonical" href="http://127.0.0.1:8001/a/a-b-c/" />'), name + 'canonical');
570571
assert.ok(output.contains('<link rel="next" href="http://127.0.0.1:8001/a/3/" />'), name + 'next');
571572
assert.ok(output.contains('<link rel="prev" href="http://127.0.0.1:8001/a/1/" />'), name + 'prev');

0 commit comments

Comments
 (0)