Comparing version 0.1.0-beta-65 to 0.1.0-beta-66
@@ -12,2 +12,3 @@ "use strict"; | ||
Type = di.load('typejs'), | ||
zlib = di.load('zlib'), | ||
core = di.load('core'), | ||
@@ -44,2 +45,3 @@ error = di.load('error'), | ||
isForwarded: Type.BOOLEAN, | ||
isCompressed: Type.BOOLEAN, | ||
encoding: Type.STRING, | ||
@@ -62,2 +64,3 @@ body: Type.OBJECT, | ||
this.isRendered = false; | ||
this.isCompressed = false; | ||
this.id = this._uuid(); | ||
@@ -437,3 +440,3 @@ }, | ||
this.request.on('data', function (body) { | ||
this.body = body; | ||
this.body = body; | ||
}.bind(this)); | ||
@@ -483,11 +486,57 @@ | ||
}.bind(this)) // handle hook chain | ||
.then(this._compress.bind(this)) | ||
.then(this._render.bind(this)) // resolve route chain | ||
.catch(this._handleError.bind(this)) // catch hook error | ||
.then(this._compress.bind(this)) | ||
.then(this._render.bind(this)) // render hook error | ||
.catch(this._handleError.bind(this)) // catch render error | ||
.then(this._compress.bind(this)) | ||
.then(this._render.bind(this)); // resolve render error | ||
}, | ||
/** | ||
* @since 0.0.1 | ||
* @author Igor Ivanovic | ||
* @method Request#_compress | ||
* | ||
* @description | ||
* Compress output | ||
* @return object | ||
*/ | ||
_compress: function Request__compress(response) { | ||
var accept = this.getRequestHeader('Accept-Encoding'), | ||
isForCompress = (Type.isString(response) || response instanceof Buffer) && !this.isCompressed; | ||
if (isForCompress) { | ||
if (accept.indexOf('gzip') > -1) { | ||
this.addHeader('Content-Encoding', 'gzip'); | ||
this.isCompressed = true; | ||
return new Promise(function (resolve, reject) { | ||
zlib.gzip(response, function (err, data) { | ||
if (err) { | ||
return reject(err); | ||
} | ||
resolve(data); | ||
}); | ||
}); | ||
} else if (accept.indexOf('deflate') > -1) { | ||
this.addHeader('Content-Encoding', 'deflate'); | ||
this.isCompressed = true; | ||
return new Promise(function (resolve, reject) { | ||
zlib.deflate(response, function (err, data) { | ||
if (err) { | ||
return reject(err); | ||
} | ||
resolve(data); | ||
}); | ||
}); | ||
} | ||
} | ||
return response; | ||
}, | ||
/** | ||
* @since 0.0.1 | ||
* @author Igor Ivanovic | ||
* @method Request#_checkContentType | ||
@@ -569,2 +618,3 @@ * | ||
}, | ||
/** | ||
@@ -571,0 +621,0 @@ * @since 0.0.1 |
@@ -5,3 +5,3 @@ { | ||
"description": "Powerful lightweight mvc framework for nodejs", | ||
"version": "0.1.0-beta-65", | ||
"version": "0.1.0-beta-66", | ||
"dependencies" : { | ||
@@ -8,0 +8,0 @@ "mongoose": "3.8.x", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
151124
4854