Skip to content

Commit 860a9bf

Browse files
committed
new changes
- added F.responseBinary() - updated contorller.binary() - removed 403 instead of connection.destroy() - added Date.toUTC()
1 parent 759eb51 commit 860a9bf

14 files changed

Lines changed: 340 additions & 88 deletions

File tree

builders.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function SchemaBuilderEntity(parent, name, obj, validator, properties) {
103103
this.parent = parent;
104104
this.name = name;
105105
this.primary;
106-
this.autotrim = true;
106+
this.trim = true;
107107
this.schema = obj;
108108
this.properties = properties === undefined ? Object.keys(obj) : properties;
109109
this.resourcePrefix;
@@ -1298,7 +1298,7 @@ SchemaBuilderEntity.prototype.make = SchemaBuilderEntity.prototype.load = functi
12981298
};
12991299

13001300
function autotrim(context, value) {
1301-
if (context.autotrim)
1301+
if (context.trim)
13021302
return value.trim();
13031303
return value;
13041304
}

changes.txt

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,42 @@
11
BETA ======= 1.8.1
22

33
- added: `config['disable-clear-temporary-directory'] = false` (after start)
4-
- added: SchemaBuilderEntity.filter(custom, [model]);
5-
- added: SchemaBuilderEntity.autotrim = true (enable/disable trim strings (default: true))
4+
- added: `SchemaBuilderEntity.filter(custom, [model])`
5+
- added: `SchemaBuilderEntity.trim = true`(enable/disable trim strings (default: true))
66
- added: cache for HTTP routing
77
- added: `config['directory-private']`
8-
- added: F.path.private([filename])
9-
- added: Controller.ping() for WebSocket
10-
- added: global.DB() --> same as global.DATABASE()
8+
- added: `F.path.private([filename])`
9+
- added: `Controller.ping()` for WebSocket
10+
- added: `global.DB()` --> same as `global.DATABASE()`
1111
- added: `config['allow-compatibility'] = true` - a backward compatibility mode (in newest version 1.9 will be set to `false`)
1212
- added: RegExp routing `F.route('/{/^\\d+$/}', ...)`
13+
- added: `F.responseBinary(req, res, contentType, buffer, [type], [download], [headers])`
14+
- added: `Date.prototype.toUTC([ticksOnly])`
1315

14-
- updated: F.route(url, ...), F.websocket(url, ...) --> URL can be function(url, req, [flags])
16+
- updated: `F.route(url, ...)`, `F.websocket(url, ...)` --> URL can be function(url, req, [flags])
1517
- updated: `config['allow-performance']` is set to true
16-
- updated: (IMPORTANT) F.map(url, filename/directory, [filter]) supports mapping directories
17-
- updated: (IMPORTANT) arguments order SchemaBuilderEntity.setValidate(function(name, value, path, model, schema){})
18-
- updated: (IMPORTANT) U.extend(target, source, [rewrite]); --> rewrite is by default: __true__
19-
- updated: SchemaBuilderEntity.setPrepare(function(name, value, index, model){}) --> __model__ is new
20-
- updated: SchemaBuilderEntity.define(name, value, required, [custom]) --> __custom__ is new
18+
- updated: (IMPORTANT) `F.map(url, filename/directory, [filter])` supports mapping directories
19+
- updated: (IMPORTANT) arguments order `SchemaBuilderEntity.setValidate(function(name, value, path, model, schema){})`
20+
- updated: (IMPORTANT) `U.extend(target, source, [rewrite]);` --> rewrite is by default: __true__
21+
- updated: `SchemaBuilderEntity.setPrepare(function(name, value, index, model){})` --> __model__ is new
22+
- updated: `SchemaBuilderEntity.define(name, value, required, [custom])` --> __custom__ is new
2123
- updated: HTML compressor
22-
- updated: favicon (removed rel="icon")
24+
- updated: favicon `(removed rel="icon")`
2325
- updated: binary `tpm create [package] [directory]` (added argument [package], [directory])
2426
- updated: better handling middleware errors and added prevention of "memory leak"
2527
- updated: (IMPORTANT): Websocket ping is set to 3 minutes
28+
- updated: framework responds for bad requests with HTTP 403
2629

2730
- removed: XSS check
2831

32+
- fixed: `controller.binary(buffer, contentType, [download], [headers])`
2933
- fixed: routing `DELETE`
30-
- fixed: binary (creating empty-project, bad record with smtp options)
34+
- fixed: `binary` (creating empty-project, bad record with smtp options)
3135
- fixed: calling generator action
32-
- fixed: binary --translate (filenames)
36+
- fixed: `binary --translate` (filenames)
3337
- fixed: SchemaBuilderEntity prepare (problem with nullable Boolean)
3438
- fixed: (IMPORTANT) 431 system route
35-
39+
-
3640
- improved: code optimalization
3741

3842
__IMPORTANT:__

index.js

Lines changed: 128 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ function Framework() {
195195

196196
this.id = null;
197197
this.version = 1810;
198-
this.version_header = '1.8.1-25';
198+
this.version_header = '1.8.1-26';
199199

200200
var version = process.version.toString().replace('v', '').replace(/\./g, '');
201201
if (version[1] === '0')
@@ -3865,6 +3865,93 @@ Framework.prototype.responseRange = function(name, range, headers, req, res, don
38653865
return self;
38663866
};
38673867

3868+
/**
3869+
* Responses binary
3870+
* @param {ServerRequest} req
3871+
* @param {ServerResponse} res
3872+
* @param {String} contentType
3873+
* @param {Buffer} buffer
3874+
* @param {String} download Optional, download name.
3875+
* @param {Object} headers Optional
3876+
* @return {Framework}
3877+
*/
3878+
Framework.prototype.responseBinary = function(req, res, contentType, buffer, encoding, download, headers, done) {
3879+
3880+
var self = this;
3881+
3882+
if (res.success || res.headersSent) {
3883+
if (done)
3884+
done();
3885+
return self;
3886+
}
3887+
3888+
req.clear(true);
3889+
3890+
if (contentType.lastIndexOf('/') === -1)
3891+
contentType = utils.getContentType(contentType);
3892+
3893+
var accept = req.headers['accept-encoding'] || '';
3894+
var compress = self.config['allow-gzip'] && REQUEST_COMPRESS_CONTENTTYPE[contentType] && accept.lastIndexOf('gzip') !== -1;
3895+
var returnHeaders = {};
3896+
3897+
returnHeaders[RESPONSE_HEADER_CACHECONTROL] = 'public';
3898+
returnHeaders['Vary'] = 'Accept-Encoding';
3899+
3900+
if (headers)
3901+
utils.extend(returnHeaders, headers, true);
3902+
3903+
download = download || '';
3904+
3905+
if (download)
3906+
returnHeaders['Content-Disposition'] = 'attachment; filename=' + encodeURIComponent(download);
3907+
3908+
returnHeaders[RESPONSE_HEADER_CONTENTTYPE] = contentType;
3909+
3910+
self.stats.response.binary++;
3911+
self._request_stats(false, req.isStaticFile);
3912+
3913+
if (req.method === 'HEAD') {
3914+
if (compress)
3915+
returnHeaders['Content-Encoding'] = 'gzip';
3916+
res.writeHead(200, returnHeaders);
3917+
res.end();
3918+
if (done)
3919+
done();
3920+
if (!req.isStaticFile)
3921+
self.emit('request-end', req, res);
3922+
return self;
3923+
}
3924+
3925+
if (compress) {
3926+
3927+
returnHeaders['Content-Encoding'] = 'gzip';
3928+
res.writeHead(200, returnHeaders);
3929+
3930+
zlib.gzip(buffer.toString(encoding || 'binary'), function(err, buffer) {
3931+
res.end(buffer);
3932+
});
3933+
3934+
if (done)
3935+
done();
3936+
3937+
if (!req.isStaticFile)
3938+
self.emit('request-end', req, res);
3939+
3940+
return self;
3941+
}
3942+
3943+
res.writeHead(200, returnHeaders);
3944+
res.end(buffer.toString(encoding || 'binary'));
3945+
3946+
if (done)
3947+
done();
3948+
3949+
if (!req.isStaticFile)
3950+
self.emit('request-end', req, res);
3951+
3952+
return self;
3953+
};
3954+
38683955
/*
38693956
Set last modified header or Etag
38703957
@req {ServerRequest}
@@ -4587,31 +4674,35 @@ Framework.prototype._request = function(req, res) {
45874674
if (self.restrictions.isAllowedIP) {
45884675
if (self.restrictions.allowedIP.indexOf(req.ip) === -1) {
45894676
self.stats.response.restriction++;
4590-
req.connection.destroy();
4677+
res.writeHead(403);
4678+
res.end();
45914679
return self;
45924680
}
45934681
}
45944682

45954683
if (self.restrictions.isBlockedIP) {
45964684
if (self.restrictions.blockedIP.indexOf(req.ip) !== -1) {
45974685
self.stats.response.restriction++;
4598-
req.connection.destroy();
4686+
res.writeHead(403);
4687+
res.end();
45994688
return self;
46004689
}
46014690
}
46024691

46034692
if (self.restrictions.isAllowedCustom) {
46044693
if (!self.restrictions._allowedCustom(headers)) {
46054694
self.stats.response.restriction++;
4606-
req.connection.destroy();
4695+
res.writeHead(403);
4696+
res.end();
46074697
return self;
46084698
}
46094699
}
46104700

46114701
if (self.restrictions.isBlockedCustom) {
46124702
if (self.restrictions._blockedCustom(headers)) {
46134703
self.stats.response.restriction++;
4614-
req.connection.destroy();
4704+
res.writeHead(403);
4705+
res.end();
46154706
return self;
46164707
}
46174708
}
@@ -4802,7 +4893,8 @@ Framework.prototype._request_continue = function(req, res, headers, protocol) {
48024893
self.emit('request-end', req, res);
48034894
self._request_stats(false, false);
48044895
self.stats.request.blocked++;
4805-
req.connection.destroy();
4896+
res.writeHead(403);
4897+
res.end();
48064898
return self;
48074899
};
48084900

@@ -4830,31 +4922,35 @@ Framework.prototype._upgrade = function(req, socket, head) {
48304922
if (self.restrictions.isAllowedIP) {
48314923
if (self.restrictions.allowedIP.indexOf(req.ip) === -1) {
48324924
self.stats.response.restriction++;
4833-
req.connection.destroy();
4925+
res.writeHead(403);
4926+
res.end();
48344927
return self;
48354928
}
48364929
}
48374930

48384931
if (self.restrictions.isBlockedIP) {
48394932
if (self.restrictions.blockedIP.indexOf(req.ip) !== -1) {
48404933
self.stats.response.restriction++;
4841-
req.connection.destroy();
4934+
res.writeHead(403);
4935+
res.end();
48424936
return self;
48434937
}
48444938
}
48454939

48464940
if (self.restrictions.isAllowedCustom) {
48474941
if (!self.restrictions._allowedCustom(headers)) {
48484942
self.stats.response.restriction++;
4849-
req.connection.destroy();
4943+
res.writeHead(403);
4944+
res.end();
48504945
return self;
48514946
}
48524947
}
48534948

48544949
if (self.restrictions.isBlockedCustom) {
48554950
if (self.restrictions._blockedCustom(headers)) {
48564951
self.stats.response.restriction++;
4857-
req.connection.destroy();
4952+
res.writeHead(403);
4953+
res.end();
48584954
return self;
48594955
}
48604956
}
@@ -7466,7 +7562,8 @@ Subscribe.prototype.multipart = function(header) {
74667562
if (self.route === null) {
74677563
framework._request_stats(false, false);
74687564
framework.stats.request.blocked++;
7469-
req.connection.destroy();
7565+
self.res.writeHead(403);
7566+
self.res.end();
74707567
return self;
74717568
}
74727569

@@ -7484,7 +7581,8 @@ Subscribe.prototype.urlencoded = function() {
74847581
self.req.clear(true);
74857582
framework.stats.request.blocked++;
74867583
framework._request_stats(false, false);
7487-
self.req.connection.destroy();
7584+
self.res.writeHead(403);
7585+
self.res.end();
74887586
return self;
74897587
}
74907588

@@ -10656,30 +10754,32 @@ Controller.prototype.redirect = function(url, permanent) {
1065610754
/**
1065710755
* A binary response
1065810756
* @param {Buffer} buffer
10757+
* @param {String} contentType
10758+
* @param {String} type Transformation type: `binary`, `utf8`, `ascii`.
10759+
* @param {String} download Optional, download name.
10760+
* @param {Object} headers Optional, additional headers.
1065910761
* @return {FrameworkController}
1066010762
*/
10661-
Controller.prototype.binary = function(buffer) {
10662-
10763+
Controller.prototype.binary = function(buffer, contentType, type, download, headers) {
1066310764
var self = this;
1066410765
var res = self.res;
10665-
10666-
if (res.success || !self.isConnected)
10766+
if (self.res.success || self.res.headersSent || !self.isConnected)
1066710767
return self;
1066810768

10669-
var req = self.req;
10670-
10671-
self.subscribe.success();
10672-
10673-
req.clear(true);
10674-
10675-
res.success = true;
10676-
res.write(buffer.toString('binary'), 'binary');
10677-
res.end();
10769+
if (typeof(type) === OBJECT) {
10770+
var tmp = type;
10771+
type = download;
10772+
download = headers;
10773+
headers = tmp;
10774+
}
1067810775

10679-
framework._request_stats(false, false);
10680-
framework.emit('request-end', req, res);
10681-
framework.stats.response.binary++;
10776+
if (typeof(download) === OBJECT) {
10777+
headers = download;
10778+
download = headers;
10779+
}
1068210780

10781+
self.subscribe.success();
10782+
framework.responseBinary(self.req, res, contentType, buffer, type, download, headers);
1068310783
return self;
1068410784
};
1068510785

minify/merged/total.js

Lines changed: 14 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

minify/total.js/builders.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ function SchemaBuilderEntity(parent, name, obj, validator, properties) {
124124
this.parent = parent;
125125
this.name = name;
126126
this.primary;
127-
this.autotrim = true;
127+
this.trim = true;
128128
this.schema = obj;
129129
this.properties = properties === undefined ? Object.keys(obj) : properties;
130130
this.resourcePrefix;
@@ -1319,7 +1319,7 @@ SchemaBuilderEntity.prototype.make = SchemaBuilderEntity.prototype.load = functi
13191319
};
13201320

13211321
function autotrim(context, value) {
1322-
if (context.autotrim)
1322+
if (context.trim)
13231323
return value.trim();
13241324
return value;
13251325
}

minify/total.js/image.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,14 @@ Image.prototype.save = function(filename, callback, writer) {
235235

236236
var cmd = exec(command, function(error, stdout, stderr) {
237237

238+
FINISHED(stdout, function() {
239+
DESTROY(stdout);
240+
});
241+
242+
// clean up
243+
cmd.kill();
244+
cmd = null;
245+
238246
self.clear();
239247
if (!callback)
240248
return;
@@ -252,6 +260,10 @@ Image.prototype.save = function(filename, callback, writer) {
252260
self.currentStream.pipe(cmd.stdin);
253261
}
254262

263+
FINISHED(cmd.stdin, function() {
264+
DESTROY(cmd.stdin);
265+
});
266+
255267
if (writer)
256268
writer(cmd.stdin);
257269

0 commit comments

Comments
 (0)