@@ -56,6 +56,7 @@ var REQUEST_COMPRESS_CONTENTTYPE = { 'text/plain': true, 'text/javascript': true
5656var TEMPORARY_KEY_REGEX = / \/ / g;
5757var REG_MOBILE = / A n d r o i d | w e b O S | i P h o n e | i P a d | i P o d | B l a c k B e r r y | I E M o b i l e | O p e r a M i n i | M o b i l e | T a b l e t / i;
5858var REG_VERSIONS = / ( h r e f | s r c ) = " [ a - z A - Z 0 - 9 \/ \: \- \. ] + \. ( j p g | j s | c s s | p n g | g i f | s v g | h t m l | i c o | j s o n | l e s s | s a s s | s c s s | s w f | t x t | w e b p | w o f f | w o f f 2 | x l s | x l s x | x m l | x s l | x s l t | z i p | r a r | c s v | d o c | d o c x | e p s | g z i p | j p e | j p e g | m a n i f e s t | m o v | m p 3 | m p 4 | o g g | p a c k a g e | p d f ) " / gi;
59+ var REQUEST_PROXY_FLAGS = [ 'post' , 'json' ] ;
5960
6061var _controller = '' ;
6162var _test ;
@@ -227,7 +228,7 @@ function Framework() {
227228
228229 this . id = null ;
229230 this . version = 1900 ;
230- this . version_header = '1.9.0-16 ' ;
231+ this . version_header = '1.9.0-17 ' ;
231232
232233 var version = process . version . toString ( ) . replace ( 'v' , '' ) . replace ( / \. / g, '' ) ;
233234 if ( version [ 1 ] === '0' )
@@ -344,6 +345,7 @@ function Framework() {
344345 packages : { } ,
345346 } ;
346347
348+ this . behaviours = null ;
347349 this . modificators = null ;
348350 this . helpers = { } ;
349351 this . modules = { } ;
@@ -462,6 +464,30 @@ Framework.prototype = {
462464
463465Framework . prototype . __proto__ = new events . EventEmitter ( ) ;
464466
467+ /**
468+ * Adds a new behaviour
469+ * @param {String } url A relative URL address.
470+ * @param {String Array } flags
471+ * @return {Framework }
472+ */
473+ Framework . prototype . behaviour = function ( url , flags ) {
474+ var self = this ;
475+
476+ if ( ! self . behaviours )
477+ self . behaviours = { } ;
478+
479+ if ( typeof ( flags ) === STRING )
480+ flags = [ flags ] ;
481+
482+ if ( ! self . behaviours [ url ] )
483+ self . behaviours [ url ] = { } ;
484+
485+ for ( var i = 0 ; i < flags . length ; i ++ )
486+ self . behaviours [ url ] [ flags [ i ] ] = true ;
487+
488+ return self ;
489+ } ;
490+
465491/**
466492 * Refersh framework internal informations
467493 * @param {Boolean } clear Clear temporary files, optional
@@ -978,6 +1004,11 @@ Framework.prototype.route = function(url, funcExecute, flags, length, middleware
9781004
9791005 var first = flags [ i ] [ 0 ] ;
9801006
1007+ if ( first === '%' ) {
1008+ self . behaviour ( url , flags [ i ] . substring ( 1 ) ) ;
1009+ continue ;
1010+ }
1011+
9811012 if ( first === '#' ) {
9821013 if ( ( middleware || null ) === null )
9831014 middleware = [ ] ;
@@ -8245,7 +8276,7 @@ Subscribe.prototype.multipart = function(header) {
82458276 }
82468277
82478278 framework . path . verify ( 'temp' ) ;
8248- framework_internal . parseMULTIPART ( req , header , self . route . length , framework . config [ 'directory-temp' ] , self ) ;
8279+ framework_internal . parseMULTIPART ( req , header , self . route , framework . config [ 'directory-temp' ] , self ) ;
82498280 return self ;
82508281} ;
82518282
@@ -8330,13 +8361,15 @@ Subscribe.prototype.execute = function(status) {
83308361 }
83318362
83328363 if ( route === null ) {
8364+ if ( ! status )
8365+ status = 404 ;
83338366 if ( status === 400 && self . exception instanceof Builders . ErrorBuilder ) {
83348367 if ( req . $language )
83358368 self . exception . resource ( req . $language , framework . config [ 'default-errorbuilder-resource-prefix' ] ) ;
83368369 framework . responseContent ( req , res , 200 , self . exception . json ( ) , 'application/json' , framework . config [ 'allow-gzip' ] ) ;
83378370 }
83388371 else
8339- framework . responseContent ( req , res , status || 404 , utils . httpStatus ( status || 404 ) , CONTENTTYPE_TEXTPLAIN , framework . config [ 'allow-gzip' ] ) ;
8372+ framework . responseContent ( req , res , status , utils . httpStatus ( status ) , CONTENTTYPE_TEXTPLAIN , framework . config [ 'allow-gzip' ] ) ;
83408373 return self ;
83418374 }
83428375
@@ -8447,6 +8480,12 @@ Subscribe.prototype.doExecute = function() {
84478480 if ( controller . isCanceled )
84488481 return self ;
84498482
8483+ if ( ! self . route . isASTERIX && ! self . route . param . length ) {
8484+ // cache internal.routeSplit()
8485+ if ( ! framework . temporary . other [ req . uri . pathname ] )
8486+ framework . temporary . other [ req . uri . pathname ] = req . path ;
8487+ }
8488+
84508489 if ( self . route . isGENERATOR )
84518490 async . call ( controller , self . route . execute , true ) ( controller , framework_internal . routeParam ( self . route . param . length ? framework_internal . routeSplit ( req . uri . pathname , true ) : req . path , self . route ) ) ;
84528491 else
@@ -8744,8 +8783,6 @@ function Controller(name, req, res, subscribe, currentView) {
87448783 this . req = req ;
87458784 this . res = res ;
87468785 this . exception = null ;
8747- this . boundary = null ;
8748-
87498786
87508787 // Sets the default language
87518788 if ( req )
@@ -11585,9 +11622,6 @@ Controller.prototype.close = function(end) {
1158511622 return self ;
1158611623 }
1158711624
11588- if ( self . type === 2 )
11589- self . res . write ( '\r\n\r\n--' + self . boundary + '--' ) ;
11590-
1159111625 self . isConnected = false ;
1159211626 self . res . success = true ;
1159311627
@@ -11628,7 +11662,7 @@ Controller.prototype.proxy = function(url, obj, fnCallback, timeout) {
1162811662 obj = tmp ;
1162911663 }
1163011664
11631- return utils . request ( url , [ 'post' , 'json' ] , obj , function ( error , data , code , headers ) {
11665+ return utils . request ( url , REQUEST_PROXY_FLAGS , obj , function ( error , data , code , headers ) {
1163211666
1163311667 if ( ! fnCallback )
1163411668 return ;
@@ -12271,7 +12305,7 @@ WebSocket.prototype.proxy = function(url, obj, fnCallback) {
1227112305 obj = tmp ;
1227212306 }
1227312307
12274- return utils . request ( url , [ 'post' , 'json' ] , obj , function ( error , data , code , headers ) {
12308+ return utils . request ( url , REQUEST_PROXY_FLAGS , obj , function ( error , data , code , headers ) {
1227512309
1227612310 if ( ! fnCallback )
1227712311 return ;
@@ -13481,6 +13515,38 @@ http.IncomingMessage.prototype.noCache = function() {
1348113515 return self ;
1348213516} ;
1348313517
13518+ http . IncomingMessage . prototype . can = function ( type , reverse ) {
13519+
13520+ if ( ! framework . behaviours )
13521+ return reverse ? false : true ;
13522+
13523+ var url = this . url ;
13524+
13525+ if ( ! this . isStaticFile && url [ url . length - 1 ] !== '/' )
13526+ url += '/' ;
13527+
13528+ var current = framework . behaviours [ '*' ] ;
13529+ var value ;
13530+
13531+ // global
13532+ if ( current !== undefined ) {
13533+ current = current [ type ] ;
13534+ if ( current !== undefined )
13535+ value = reverse ? ! current : current ;
13536+ }
13537+
13538+ // by specific
13539+ current = framework . behaviours [ url ] ;
13540+ if ( current === undefined )
13541+ return value ; // responds with global
13542+
13543+ current = current [ type ] ;
13544+ if ( current === undefined )
13545+ return value ; // responds with global
13546+
13547+ return reverse ? ! current : current ;
13548+ } ;
13549+
1348413550/**
1348513551 * Read a cookie from current request
1348613552 * @param {String } name Cookie name.
@@ -13667,7 +13733,7 @@ function fsStreamRead(filename, options, callback, next) {
1366713733
1366813734/**
1366913735 * Prepare URL address to temporary key (for caching)
13670- * @param {ServerRequest or Strign } req
13736+ * @param {ServerRequest or String } req
1367113737 * @return {String }
1367213738 */
1367313739function createTemporaryKey ( req ) {
0 commit comments